$population = array('New York' => array('state' => 'NY', 'pop' => 8008278),
'San Antonio' => array('state' => 'TX', 'pop' => 1144646),
'Detroit' => array('state' => 'MI', 'pop' => 951270));
$state_totals = array();
$total_population = 0;
print "City Population \n";
foreach ($population as $city => $info) {
$total_population += $info['pop'];
$state_totals[$info['state']] += $info['pop'];
print "$city, {$info['state']} {$info['pop']} \n";
}
foreach ($state_totals as $state => $pop) {
print "$state $pop \n";
}
print "Total $total_population \n";
print "
\n";
?>