note 42573 added to function.current

From: Date: Fri, 21 May 2004 20:49:01 +0000
Subject: note 42573 added to function.current
Groups: php.notes 
Request: Send a blank email to php-notes+get-69923@lists.php.net to get a copy of this message
[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"; } ---- Manual Page -- http://www.php.net/manual/en/function.current.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42573 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42573&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42573&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69923) next »