开发者

php array_sum on associative array

I have associative array (dynamic-may have more arrays but same keys):

  Array
 (
    [food] => Array
      (
        [0] => 3
        [1] => 4
        [2] => 1
      )

     [liquor] => Array
       (
         [0] => 4
         [1] => 5
         [2] => 0
       )

     [beer] => Array
      (
        [0] => 5
        [1] => 6
        [2] => 0
      )

  )

I need to us开发者_Python百科e array_sum on each array so result would be:

Array ( [food] => 8, [liquor] => 9, [beer] => 11 )

Thanks!


$result = array_map('array_sum', $your_array);

Example: http://ideone.com/LqTAV

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜