How can I reset an array in PHP?
This is easily done with the reset function, like this:
reset($array);
This returns the first element and sets it as the current element.
Here is a little example just to make this technique clear:
<?php
$numbers = array("Item 1","Item 2","Item 3");
next($numbers);
$thisvalue = current($numbers); echo "We are now at $thisvalue\n\n";
$first = reset($numbers);
echo "Back to $first";
?>
Printing:
We are now at Item 2
Back to Item 1
More arrays PHP Questions
How do I sort an array by key?How do I pick a random value from an array?
How do you remove duplicate values from an array?
How do I remove and view the last element of an array?
How do I find the size of an array?