UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> how to display first key in a 2 dimentional array    
 
   
Nyteshade
post Nov 27 2009, 05:05 PM
Post #1

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



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();
}
}
?>
Go to the top of the page
 
+
Nyteshade
post Dec 2 2009, 08:22 AM
Post #2

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



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?!?
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 09:45 AM