开发者

count element in array? [duplicate]

This question already has answers here: Working with arrays in php (4 answers) Closed 3 years ago. 开发者_Python百科

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 ) )


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜