note 42106 added to function.current
| From: | turadg at berkeley dot edu | Date: | Mon, 03 May 2004 18:14:27 +0000 |
| Subject: | note 42106 added to function.current | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69162@lists.php.net to get a copy of this message | ||
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";
}
----
Manual Page -- http://www.php.net/manual/en/function.current.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42106
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42106&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42106&report=yes
Search -- http://master.php.net/manage/user-notes.php