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


Please Help Members By Posting Answers For Below Questions

Is key exist in array php?

530


What is the difference between explode() and split() functions?

496


How to replace a substring in a given string in php?

541


Explain me what are the 3 scope levels available in php and how would you define them?

721


How to find the position of the first occurrence of a substring in a string?

496






What is the use session in php?

542


What is the use of $_server and $_env?

559


What is use of htmlspecialchars php?

508


Which one is best framework for php?

494


Tell us how to set cookies in php?

529


How to access a specific character in a string using php?

508


Is empty check in php?

556


Does php have future?

572


What is php how it works?

528


What the limitation of header() function in php?

501