note 32903 added to control-structures.foreach
| From: | php at electricsurfer dot com | Date: | Tue, 10 Jun 2003 15:11:13 +0000 |
| Subject: | note 32903 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50107@lists.php.net to get a copy of this message | ||
Here's an easy way of seeing if you are on the 1st iteration of a foreach loop:
$list = array('Bananas'=>6,'Apples'=>5,'Oranges'=>3);
foreach (array_keys($list) as $i=>$item)
{
if ($i) echo ', ';
echo $list[$item].' '.$item;
}
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32903
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32903&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32903&report=yes