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

What is http php?

0 Answers  


How do I find environment variables?

0 Answers  


What is the delimiter syntax is PHP's default delimiter syntax

0 Answers  


What is different between software and app

0 Answers  


How can I load data from a text file into a table?

0 Answers  






Why is PHP-MySQL frequently used for web (Portal) Development?

5 Answers   T3 Softwares, Wipro,


What are the different components used in php for formatting?

0 Answers  


What is the difference between require_once and require in php?

0 Answers  


What is final class and final method?

0 Answers  


Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally, the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.

1 Answers   Wipro,


Is php case sensitive?

0 Answers  


What is the difference between ereg_replace() and eregi_replace()?

2 Answers   Quicknet,


Categories