Mega Code Archive
Use for each to loop through an array and create a table
$population = array('New York, NY' => 8008278,
'Los Angeles, CA' => 3694820,
'Chicago, IL' => 2896016);
$total_population = 0;
print "City | Population |
\n";
foreach ($population as $city => $people) {
$total_population += $people;
print "$city | $people |
\n";
}
print "Total | $total_population |
\n";
print "
\n";