multi dimensional array question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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...
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux