note 20087 deleted from function.next by aidan

From: Date: Sat, 18 Sep 2004 04:32:14 +0000
Subject: note 20087 deleted from function.next by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76911@lists.php.net to get a copy of this message
Note Submitter: nikolai@bigaction_dot_org ---- > Don't try this and expect it to work: > > while(next($array)) > > the loop will never begin on the first item in the array > since next() advances the pointer BEFORE returning > the values. reset() returns the first element in the array, so it's not such a bad thing that next() returns the second. To avoid the overhead of using list() with each(), you can simply do this: $elem = reset($your_array) do { //.. stuff with $elem; } while($elem = next($your_array)); this is, of course, assuming that the array is not empty, but it's easy to wrap the whole thing in an if().

« previous php.notes (#76911) next »