This is the shortest function
I could come up with.
function will test if element is_array
and add result of a recursive call if it is
otherwise it will just add value, $val
<?php
function sum_array($arr){
$res = 0;
foreach($arr AS $val)
$res += is_array($val)? sum_array($val) : $val;
return $res;
}
$myArray = array (0=>19,
1=>32,
2=>array(0=>12,1=>15),
3=>9,
4=>array(0=>2,1=>5)
);
echo sum_array($myArray); // will display 94
?>