In my php script, I have a variable $data that contains an array that may have various number of elements.
The script picks one of the array elements at random and outputs it to the browser:
# count number of elements in $data
$n = count($data);
# pick a random number out of the number of elements in $data
$rand = rand(0, ($n - 1));
# output a random element
echo '<p> . trim($data[$rand]) . '</p>';
QUESTION: I want to improve that script, so that it doesn't output the same array element again until it runs out of array elements. For example, if an array contains elements numbered 0 to 9, and the script picked an array element #4, I want it to remember that, and next time the script runs, to exclude the element that was #4.
It could probably be done in many different ways, but I'm looking for the simplest and most elegant solution, and would be grateful for help from a PHP expert.