multi dimensional array question
| From: | Nick Balestra | Date: | Fri, 30 Apr 2010 22:57:01 +0000 |
| Subject: | multi dimensional array question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-304794@lists.php.net to get a copy of this message | ||
hello everybody here is my array(s)
$us_census = array('NY' => array('New York' => 8008278),
'CA' => array('Los Angeles' => 3694820,
'San Diego' => 1223400),
'IL' => array('Chicago' => 2896016),
'TX' => array('Houston' => 1953631,
'Dallas' => 1188580,
'San Antonio' => 1144646),
'PA' => array('Philadelphia' => 1517550),
'AZ' => array('Phoenix' => 1321045),
'MI' => array('Detroit' => 951270));
print
"<table><tr><th>State</th><th>City</th><th>Population</th><th>Total</th></tr>";
// $state is the key and $states is the value
foreach ($us_census as $state => $cities) {
// $state is the key and $habitant is the value
foreach ($cities as $city => $habitants){
print
"<tr><td>$state</td><td>$city</td><td>$habitants</td><td></td></tr>";
}
}
Now i also want to be able to count the total population per state, i am stucked...