View Single Post
Old 02-07-2010, 03:08 AM   #1 (permalink)
aquastream
The Wanderer
 
Join Date: Feb 2010
Posts: 6
Thanks: 1
aquastream is on a distinguished road
Default Inconsistencies in foreach Working

Here's another newbie question which I'm confused about. I've used the foreach function to list the contents of the first array. However, on the second array I can't get the same results. I simply get the last result echoed and the other ones are ignored.

<?php
$array1 = array("Lisa" => 28,"Jack" => 16,"Ryan" => 35,"Rachel" => 46,"Grace" => 34);
foreach($array1 as $names => $numbers)
echo "Name: $names, Age: $numbers <br />"
?>
<br />
<?php
$beatles = array("Singer 1" => "Paul","Singer 2" => "John","Guitarist" => "George","Drummer" => "Ringo");
foreach($beatles as $roles => $names);
echo "$roles: $names <br />"
?>

Can anyone see what I've done wrong here?
Thanks
aquastream is offline  
Reply With Quote