loops - PHP, echo one specific value from multiple associative arrays in a multidimensional array -


i want output first name each array. comments in code below explain. not want keys, value. see describe below, love have loop produce desired results. there loop return 'firstname' values only? thanks....


<?php $contacts = array(     array(         'firstname' => "hoth",         'lastname' => "omiaenoed",         'address'=> "76 s. mammoth st.",         'city' => "westfield",         'state' => "ma",         'zip' => "01085",     ),     array(         'firstname' => "akae",         'lastname' => "uniaebul",         'address'=> "8038 shadow brook street",         'city' => "ocoee",         'state' => "fl",         'zip' => "34761",     ),     array(         'firstname' => "upae",         'lastname' => "aesuudoes",         'address'=> "7044 n. school st.",         'city' => "riverdale",         'state' => "ga",         'zip' => "30274",     ),     array(         'firstname' => "doer",         'lastname' => "waezoeyo",         'address'=> "338 old griffin st.",         'city' => "antioch",         'state' => "tn",         'zip' => "37013",     ),     array(         'firstname' => "ozae",         'lastname' => "iraeoewif",         'address'=> "65 west chapel dr.",         'city' => "san angelo",         'state' => "tx",         'zip' => "76901",     ),     array(         'firstname' => "naes",         'lastname' => "ebaeaeraesh",         'address'=> "34 tower street",         'city' => "huntersville",         'state' => "nc",         'zip' => "28078",     ) );  /* want echo (print) first names each array. hoped use "foreach" loop , seemed me 1 below should work */  foreach ($contacts['firstname'] $fname) {     while (list( , $firstn) = each($fname)) {         echo "$firstn <br/>";     }     echo "------------------------------------------<br/>"; }  /* not. adding in ['firstname'] not work. so, have use 1 below, lack of knowing else do. */  echo $contacts[0]['firstname']; echo "<br/>"; echo "------------------------------------------<br/>"; echo $contacts[1]['firstname']; echo "<br/>"; echo "------------------------------------------<br/>"; echo $contacts[2]['firstname']; echo "<br/>"; echo "------------------------------------------<br/>"; echo $contacts[3]['firstname']; echo "<br/>"; echo "------------------------------------------<br/>"; echo $contacts[4]['firstname']; echo "<br/>"; echo "------------------------------------------<br/>"; echo $contacts[5]['firstname']; echo "<br/>"; echo "------------------------------------------<br/>";  /* used output each complete array , works fine. */  foreach ($contacts $info) {     while (list( , $lines) = each ($info)) {         echo "$lines <br/>";     }     echo "<hr/>"; }      ?> 

 foreach ($contacts $contact)  {   echo $contact['firstname'];  } 

Comments