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 are the uses of php language?
What is csrf token in php?
Tell me how to strip whitespace (or other characters) from the beginning and end of a string?
Where can I find php ini file?
How to submit form without a submit button.
When to use inquire vs enquire?
What is php and sql used for?
What is restful api?
What is the difference between indexed and associative array?
What is difference between require_once(), require(), include()?
Does php require a web server?
Write a program in php to print a table of a number?
Why constructor is not overridden?
What is csrf token and why it is required?
What is the delimiter syntax is PHP's default delimiter syntax