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 best php framework 2018?
How to close a session properly?
What is the difference between the include() and require() functions?
What is the difference between $argv and $argc? Give example?
Write a program to show the joining of two strings in php?
How to reset/destroy a cookie in php?
How to read a file in php?
Explain type casting and type juggling.
Tell me which function gives us the number of affected entries by a query?
Php error constants and their descriptions
How to create a mysql connection?
What is difference between rest api and restful api?
Who is the father or inventor of php?
Does php have multiple inheritance?
Why overriding is called runtime polymorphism?