tags:

views:

49

answers:

2

I have an Array like this (when I print_r). How can I sum all elements in this Array? In this example, the sum is 0+1=1

Array ( [0] => Array ( [0] => 0 )
        [1] => Array ( [0] => 1 ) )
A: 

Take a look at the 'array_reduce' function: array_reduce: http://nl.php.net/manual/en/function.array-reduce.php

Taken from the documentation:

function rsum($v, $w)
{
    $v += $w;
    return $v;
}
$sum = array_reduce($a, "rsum");
TheGrandWazoo
+2  A: 

Take a look at array_sum

Soufiane Hassou