On 30 April 2010 23:57, Nick Balestra <[email protected]> wrote:
> 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));
<?php
$us_census = array ( ... );
function Sum($a, $b) {
return $a + (is_array($b) ? array_reduce($b, 'Sum') : $b);
}
echo array_reduce($us_census, 'Sum');
?>
outputs ...
23899236
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling