note 59045 added to function.each
| From: | amby2 at izh dot com | Date: | Thu, 24 Nov 2005 17:55:14 +0000 |
| Subject: | note 59045 added to function.each | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99045@lists.php.net to get a copy of this message | ||
I've found a compact way to cycle through an associative array using for statement (not while,
as it has been done in the most of examples below):
<?php
for (reset($array); list($key) = each($array);) {
echo $key;
echo $array[$key];
}
?>
or
<?php
for (reset($array); list($key, $value) = each($array);) {
echo $key;
echo $value;
echo $array[$key];
}
?>
You hardly forget to add reset($array) code line using such construction.
----
Manual Page -- http://www.php.net/manual/en/function.each.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59045
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59045&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59045&report=yes
Search -- http://master.php.net/manage/user-notes.php