Re: multi dimensional array question

From: Date: Fri, 30 Apr 2010 23:23:20 +0000
Subject: Re: multi dimensional array question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-304796@lists.php.net to get a copy of this message
Am 01.05.2010 00:57, schrieb Nick Balestra: > 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... > array_sum() should do it :) foreach ($us_census as $state => $cities) { $population_per_state = array_sum($cities); }

« previous php.general (#304796) next »