如何使用foreach循环对此空数组进行排序,以便按顺序输出这25个数字?
示例结果将是:1 1 1 1 1 2 2 2 2 3 3 3 3 3 4 4 4 4
<?php
$array = array();
for($counter = 0; $counter <=25; $counter++){
$die = rand(1, 10);
$int[$counter] = $die;
echo " $die ";
}
sort($die);
foreach ($die as $value)
{
echo '<option value="'.$value.'">'.$value.'</option>';
}
?>
答案 0 :(得分:0)
<?php
$array = array();
for ($i = 0; $i <=25; $i++) {
echo $array[] = rand(1, 10);
}
sort($array);
foreach ($array as $value) {
echo '<option value="'.$value.'">'.$value.'</option>';
}