note 42106 deleted from function.current by nlopess
| From: | nlopess@php.net | Date: | Sat, 22 May 2004 08:16:23 +0000 |
| Subject: | note 42106 deleted from function.current by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69938@lists.php.net to get a copy of this message | ||
Note Submitter: turadg@berkeley.edu
----
I find current() very useful to peek ahead in a foreach() iteration. This works because when the
block begins, foreach has already selected the element and advanced the pointer.
Another handy trick is to use current() to see if the current block is processing the last element
of the array.
$stepArray = array("first", "second", "third");
foreach ($stepArray as $step) {
$afterThis = current($stepArray);
if (empty($afterThis)) print "$step is the last element; there are no more";
}