我有一个存储0到5之间的数字范围的数组,当页面加载时,数组被洗牌。当提交带有下拉选项的表单时,我希望数组以与以前相同的顺序返回。
$game=range(0,5);
shuffle($game);
echo implode ("," , $game);
<form method ="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<select name="values">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" name="game" value="Play">
</form>
答案 0 :(得分:0)
如果您使用srand()
或mt_srand()
为每个随机数生成器播放相同的值,那么它将以相同的方式“随机化”它:
$game=range(0,5);
srand(2016); // whatever value you like, could easily be just 1
shuffle($game);
print_r($game);