How can I reset an array in PHP?

Answers were Sorted based on User's Feedback



How can I reset an array in PHP? ..

Answer / 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

How can I reset an array in PHP? ..

Answer / ram

The reset () function moves the internal pointer to the
first element of the array. This function returns the value
of the first element in the array on success, or FALSE on
failure.
Syntax: reset(array)

<?php
echo date("Y-m-d");
$people = array("Prasad", "Ram", "vidhya");

echo current($people) . "<br />";
echo next($people) . "<br />";

echo reset($people);
?>

Is This Answer Correct ?    10 Yes 1 No

How can I reset an array in PHP? ..

Answer / madipally

Its very simple uday,

we have an array of numbers , which contains
"Item1","Item2","Item3".

when we call next($numbers) , the pointer will be jump to
the next item, in this case Item2.After resetting using
reset($numbers) pointer will move to the first location that
is "Item1".

Is This Answer Correct ?    7 Yes 4 No

How can I reset an array in PHP? ..

Answer / uday

hello ur answer is too difcult to learn plz answer in
simple very complicated

Is This Answer Correct ?    3 Yes 11 No

Post New Answer

More PHP Interview Questions

How to receive a cookie from the browser?

0 Answers  


Different between the var_dump() and print_r()?

4 Answers  


Which is correct about mysqli and pdo?

0 Answers  


What is the differences between $a != $B and $a !== $B?

0 Answers  


hi abinashg i think u have experience in php plz tell me more about php now i raearlly want to do php wat is the future.my email id atul_saini2@yahoo.co.in.plz guide me thanks...........

2 Answers  


What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, servers and operating systems?

3 Answers  


Who is known as the father of php?

0 Answers  


Is rent a variable cost?

0 Answers  


Which is incorrect with respect to separating php code and html?

0 Answers  


What is isset in php?

0 Answers  


What are the special characters you need to escape in single-quoted stings?

0 Answers  


What is mean tnq

0 Answers   TNQ,


Categories