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
What is the ioncube php loader?
what is session_set_save_handler in PHP?
Is key in array php?
What is meant by variable variables in php?
What is php addslashes?
What is strlen php?
How to strip whitespace (or other characters) from the beginning and end of a string?
What are the uses of implode() function?
How to get a random value from a php array?
How to break a file path name into parts?
How to define a function with any number of arguments?
Explain the value of the variable input is a string 1,2,3,4,5,6,7. How would you get the sum of the integers contained inside input?
How check variable is set or not in php?
What is __ invoke in php?
How is it possible to propagate a session id?