php - array for loop syntax -


if have:

$data = array(   'id01' => array(     'firstname' => 'eric',     'lastname' => 'smith',   ),   'id02' => array(     'firstname' => 'john',     'lastname' => 'turner',   ), );  foreach ( $data $key){     print "$key[firstname]<br>";     echo $key[0]; } 

the $key[0] part not working...basically i'm trying output id01, id02, id part of array forloop processing...

any ideas on correct syntax?

what need

foreach ($data $key => $val){     print "$val[firstname]<br>"; //changed $val     echo $key; //prints id01, id02 } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -