$allnum = 10;
$min = 10;
$max = 50;
function randomnum($a, $b, $c) { // สุ่มเลข
for ($i = 0; $i < $a; $i++) {
$random[$i] = rand($b, $c);
}
return $random;
}
function sl($a, $b) { // เรียงลำดับจากเลขที่สุ่ม
for ($i = 0; $i < $a; $i++) {
$sor[$i] = sort($b);
} return $sor;
}
//--------------------------------------------------------
$rand = randomnum($allnum, $min, $max);
echo "<pre>";
print_r($rand);
echo "</pre>";
$slor = sl($allnum, $rand);
echo "<pre>";
print_r($slor);
echo "</pre>";
//--------------------------------------------------------
ผลลัพธ์
Array
(
[0] => 24
[1] => 30
[2] => 42
[3] => 44
[4] => 16
[5] => 25
[6] => 33
[7] => 39
[8] => 11
[9] => 26
)
Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 1
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
)
คำถามคือ ทำไมข้อมูลชุดสุดท้ายถึงเป็น 1 หมดเลยครับ
ช่วยดูโค้ด php หน่อยครับ
$min = 10;
$max = 50;
function randomnum($a, $b, $c) { // สุ่มเลข
for ($i = 0; $i < $a; $i++) {
$random[$i] = rand($b, $c);
}
return $random;
}
function sl($a, $b) { // เรียงลำดับจากเลขที่สุ่ม
for ($i = 0; $i < $a; $i++) {
$sor[$i] = sort($b);
} return $sor;
}
//--------------------------------------------------------
$rand = randomnum($allnum, $min, $max);
echo "<pre>";
print_r($rand);
echo "</pre>";
$slor = sl($allnum, $rand);
echo "<pre>";
print_r($slor);
echo "</pre>";
//--------------------------------------------------------
ผลลัพธ์
Array
(
[0] => 24
[1] => 30
[2] => 42
[3] => 44
[4] => 16
[5] => 25
[6] => 33
[7] => 39
[8] => 11
[9] => 26
)
Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 1
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
)
คำถามคือ ทำไมข้อมูลชุดสุดท้ายถึงเป็น 1 หมดเลยครับ