PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How can I reset an array in PHP?


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";
?>


Printing:

We are now at Item 2

Back to Item 1



Comment on this Question and Answer >>>

ASK A QUESTION

More arrays PHP Questions

How can I display values in a two dimensional array?

How can I create an array of numbers easily?

How can I loop through the members of an array?

How do I find out if a value is already in an array?

How do I check if a variable is of array type?



Custom Search