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

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



ASK A QUESTION

More arrays PHP Questions

How do I change: function wordlimit($string, $length = 50, $ellipsis = "...") { $words = explode(' ', strip_tags($string)); if (count($words) > $length) return implode(' ', array_slice($words, 0, $length)) . $ellipsis; else

when i fetch the record in the database but they skip first record in the database

Hi. i have a music samples website. in one table, id like a different sample to appear every time the page is refreshed. how do i acheve this? how can i alterate and retrieve these bloody mp3's? surely i can use a PHP script? thankyou

How do I generate an associative array like Jan => 10, Feb =>20 etc from a mysql table of 2 columns, month and val ?

I have an array of numbers and many repeat, how to list all items in order of maximum occurence?



Custom Search