note 42573 deleted from function.current by nlopess
| From: | nlopess@php.net | Date: | Sat, 22 May 2004 08:16:20 +0000 |
| Subject: | note 42573 deleted from function.current by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69937@lists.php.net to get a copy of this message | ||
Note Submitter: turadg@berkeley.edu
----
[My previous note is incorrect. Please replace it with the following:]
I find next() very useful to peek ahead in a foreach() iteration. This works because the sequence
that foreach uses is independent of the internal array pointer.
Another handy trick is to use next() to see if the current block is processing the last element of
the array.
$stepArray = array("first", "second", "third");
foreach ($stepArray as $step) {
$afterThis = next($stepArray);
if (empty($afterThis)) print "$step is the last element; there are no more";
}