-1
我有以下代码:在PHP阵列产生随机数
<?php
function randomGen($min, $max, $quantity) {
$numbers = range($min, $max);
shuffle($numbers);
return array_slice($numbers, 0, $quantity);
}
for ($row = 0; $row < 5; $row++) {
echo "<p><b>Set: $row</b></p>";
print_r(randomGen(1,36,6));
}
//}//}
?>
其例如输出:
Set: 0
Array ([0] => 32 [1] => 35 [2] => 22 [3] => 29 [4] => 8 [5] => 17)
Set: 1
Array ([0] => 25 [1] => 28 [2] => 8 [3] => 30 [4] => 13 [5] => 9)
Set: 2
Array ([0] => 24 [1] => 31 [2] => 33 [3] => 28 [4] => 2 [5] => 32)
Set: 3
Array ([0] => 1 [1] => 6 [2] => 33 [3] => 2 [4] => 14 [5] => 29)
Set: 4
Array ([0] => 17 [1] => 25 [2] => 6 [3] => 15 [4] => 24 [5] => 22)
但是我想为结果显示为:只的数量,实施例:
32 35 22 29 8 17
ETC,我怎么能去删除它们
'implode(“”,randomGen(1,36,6))'是你想要的吗? – 2014-09-12 17:39:04
那么当我尝试了implode(“”,randomGen(1,36,6))它不会返回任何值 – dames 2014-09-12 17:42:42
implode本身只是返回一个字符串,您需要回显当然。 – 2014-09-12 17:46:29