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
Explain preg_Match and preg_replace?
What are escaping characters?
Which function gives us the number of affected entries by a query?
Is set in php?
Why overriding is called runtime polymorphism?
What is abstraction php?
How can a cross-site scripting attack be prevented by php?
What is a namespace in php?
Is it possible to submit a form with a dedicated button?
What is list in PHP?
What are the string functions in php?
Do you know what are traits?
where do we use htaccess?
Which function would you use to format date information in php?
How many types of php frameworks are there?