开发者

php array_sum on associative array

开发者 https://www.devze.com 2023-04-09 05:12 出处:网络
I have associative array (dynamic-may have more arrays but same keys): Array ( [food] => Array ( [0] => 3

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

精彩评论

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