I have an array that stores a range of numbers between 0 and 5 and when the page loads the array is shuffled. When a form with drop-down options gets submitted I want the array to return in the same sequence as before.
$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>
If you seed the random number generator with the same value each time using srand()
or mt_srand()
then it will "randomize" it the same way:
$game=range(0,5);
srand(2016); // whatever value you like, could easily be just 1
shuffle($game);
print_r($game);