note 50465 added to control-structures.foreach
| From: | magnus_nirgi at hotmail dot com | Date: | Tue, 01 Mar 2005 12:03:40 +0000 |
| Subject: | note 50465 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85708@lists.php.net to get a copy of this message | ||
Weird problem with FOREACH loop. Didn't find help at first RTFM. Anyway here's the
situation:
$fruits = array("one" => "apple", "one" => "orange");
foreach($fruits as $key => $fruit)
echo $key." = ".$fruit;
Will produce "one = orange".
$fruits = array("one" => "apple", "two" => "lemon",
"one" => "orange");
foreach($fruits as $key => $fruit)
echo $key." = ".$fruit;
Will produce "one = orange" and "two = lemon".
So it kinda prints value of LAST recurring element with index "one" and drops the earlier
occured ones out.
I need FOREACH to handle (in this case echo) all the itmes in array.
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50465
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50465&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50465&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50465&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50465&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50465&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50465&report=yes
Search -- http://master.php.net/manage/user-notes.php