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
Comment on this Question and Answer >>>
ASK A QUESTION
More arrays PHP Questions
How do I remove an element from an array without changing the index values for the rest of the array?when i fetch the record in the database but they skip first record in the database
How do I find the size of an array?
I have an array of a hundred or so lines, each line has data with "|" separated values. I need to scan through this array, and select the line whose first 5 characters matches a text string. Any ideas or questions?
How do I add to the end of an array and know how large the array is?
