Full Version: how to display first key in a 2 dimentional array
UtterAccess Discussion Forums > And More... > PHP, Perl, MySQL and Postgres
Nyteshade
I have an array set up and what I am doing is learning how to use php functions, global vars, and looping; so this is an excersize for me. It works just fine but I can not figure out how to display the two position state abbreviation in the output. When I use the variable $state then the value displayed is 'array'. Help, thx all!

CODE
<?php
$statecapitals['AL']['Alabama']='Montgomery';
$statecapitals['AK']['Alaska']='Juneau';
$statecapitals['AZ']['Arizona']='Phoenix';
$statecapitals['AR']['Arkansas']='Little Rock';

    
     function format_display()
{
     global $capitalState, $city;
     echo "The capital of $capitalState is $city.<br>";
     return;
}
     foreach ($statecapitals as $state)
{
     foreach ($state as $capitalState => $city)
{
     format_display();
}
}
?>
Nyteshade
I know how to retrieve all the columns using list() and extract(), so getting the value of all the columns is not a problem for me. I just wondered why I can't get that first key with my foreach loop. Hmmm, and no comments?!?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.