note 50465 deleted from control-structures.foreach by aidan
| From: | aidan@php.net | Date: | Sat, 12 Mar 2005 00:37:36 +0000 |
| Subject: | note 50465 deleted from control-structures.foreach by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-86311@lists.php.net to get a copy of this message | ||
Note Submitter: magnus_nirgi at hotmail dot com
----
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.