How can I reset an array in PHP?
Answer Posted / jude jeevanraj.p
Sometimes if you are moving through the various elements in
an array, you will want to return the pointer to the
beginning of the array.
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";
?>
| Is This Answer Correct ? | 21 Yes | 1 No |
Post New Answer View All Answers
Why super () is used in java?
What is the use of return in php?
How values in arrays are indexed?
Is php developer in demand?
Is php still used?
What is the difference between implode() and explode() in php?
What are the new features in php 7?
Tell me what type of operation is needed when passing values through a form or an url?
What is the use of stripslashes in php?
Is empty array php?
What is a base url?
How many keywords are there in php?
Explain me what is the difference between explode() and split() functions?
What is member variable?
Tell me is it possible to submit a form with a dedicated button?