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
Is key exist in array php?
What is the difference between explode() and split() functions?
How to replace a substring in a given string in php?
Explain me what are the 3 scope levels available in php and how would you define them?
How to find the position of the first occurrence of a substring in a string?
What is the use session in php?
What is the use of $_server and $_env?
What is use of htmlspecialchars php?
Which one is best framework for php?
Tell us how to set cookies in php?
How to access a specific character in a string using php?
Is empty check in php?
Does php have future?
What is php how it works?
What the limitation of header() function in php?