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 reverse sort an array by key?How can I sort a multi-dimensional array?
HOW CAN I DELETE ALL THE ELEMENT OF THE ARRAY
I have the following list : Tom T1 Tom T2 Bill T1 Bill T2 Jack T1 Jack T2 I need it converted into : Tom T1,T2 Bill T1,T2 Jack T1,T2
How do I pick a random value from an array?
