|
 |
|
random เอาจำนวนตัวเลขมา 5 ตัวเลข ผมต้องการเอาตัวเลขมา 5 ตำแหน่ง |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
$int = rand(1,50);
for ($i=0;$i<=4;$i++)
{
$new=$int+$i;
if ($new>50)
{
echo ($new-50).'<br />';
}else{
echo $new.'<br />';
}
}
?>
|
 |
 |
 |
 |
Date :
2009-08-03 11:02:35 |
By :
ongsa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$size = 50;
$get_size = 5;// เอามา 5
$nums = rage(1, $size);
$now_index = $start_index = rand(0, $size-1);// สุ่ม index ในอาเรย์(50)
do{
if( $now_index < ($size -1) ){
echo $
?>
... ต้องรีบไปแล้ว มีคนเรียก
|
 |
 |
 |
 |
Date :
2009-08-03 11:12:38 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณเอี่ยว รีบซะขนาดนี้ แสดงว่างานเข้า 
|
 |
 |
 |
 |
Date :
2009-08-03 11:20:41 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ คุณ ongsa ,เอี่ยว
|
 |
 |
 |
 |
Date :
2009-08-03 14:13:52 |
By :
pun05 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามเรพ 1 กรณีที่ตัวเลขมันต่อกันอ่ะนะ ถ้ามีค่าโดดมันก็จะไม่ถูก ตามความเข้าใจผมว่าเป็นอาเรย์นะ
มาเขียนต่อ
Code(PHP)
<?php
$size = 50;
$get_size = 5;// เอามา 5
$nums = rage(1, $size); //สร้าง array มาทดสอบ
$now_index = $start_index = rand(0, $size-1);// สุ่ม index ในอาเรย์(50)
do{
echo $nums[$now_index], ' ';
$now_index = $now_index < $size ? ++$now_index : 0;
$i++;
}while($i <= $get_size);
?>
SITE: http://gunner.freetzi.com/newVer
MSN: [email protected]
TEL: 087-577-0276
|
 |
 |
 |
 |
Date :
2009-08-03 17:15:32 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยน เป็น range() ครับ พิมพ์ผิด
|
 |
 |
 |
 |
Date :
2009-08-04 20:04:38 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มให้อีกนิดนะ
Code (PHP)
<?php
<?php
$size = 50;
$get_size = 5;// เอามา 5
$nums = range(1, $size); //สร้าง array มาทดสอบ
$now_index = $start_index = rand(0, $size-1);// สุ่ม index ในอาเรย์(50)
do{
echo ($i ? ',' : ''), $nums[$now_index], ' ';
$now_index = $now_index < $size ? ++$now_index : 0;
$i++;
}while($i <= $get_size);
?>
?>
|
 |
 |
 |
 |
Date :
2009-08-04 20:07:05 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาไปลองมาละ bug เพียบ
Code (PHP)
<?php
$size = 50;
$get_size = 5;// เอามา 5
$nums = range(1, $size); //สร้าง array มาทดสอบ
$now_index = $start_index = rand(0, $size-1);// สุ่ม index ในอาเรย์(50)
do{
echo ($i ? ', ' : ''), $nums[$now_index];
$now_index = $now_index < ($size-1) ? ++$now_index : 0;
$i++;
}while($i < $get_size);
?>
โอเคละ 555
|
 |
 |
 |
 |
Date :
2009-08-05 07:36:23 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองแล้วได้ตามที่ต้องการเลย
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-08-05 11:39:05 |
By :
pun05 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|