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

can we swap two different string using php for example:-- before swapping:-- 1 string :-hello friend, 2 string :-my dear, after swapping that strings will be: 1.hello dear, 2.my friend.

0 Answers  


what is constructor in a class, how it is work, how it is call?

2 Answers  


How to find out, how a user visited a particular page?

4 Answers   Yahoo,


How to set cookies in PHP?

0 Answers  


What is csrf validation?

0 Answers  






What interest would a "work-for-ownership" offer receive from PHP/MySQL developers?

1 Answers  


Is php harder than javascript?

0 Answers  


How does csrf attack work?

0 Answers  


What is a comment in php?

0 Answers  


Is laravel easy to learn?

0 Answers  


What is the difference between urlencode and urldecode ?

3 Answers  


Tell me what is the importance of "action" attribute in a html form?

0 Answers  


Categories