How to sum all column values in multi-dimensional array?

后端 未结 20 2524
花落未央
花落未央 2020-11-22 00:57

How can I add all the columnar values by associative key? Note that key sets are dynamic.

Input array:

Arr         


        
20条回答
  •  天涯浪人
    2020-11-22 01:39

    For example, you can pluck all fields from a result like this below.

    I am picking out the 'balance' from an array and save to a variable

    $kii =   $user->pluck('balance');
    

    then on the next line u can sum like this:

    $sum =  $kii->sum(); 
    

    Hope it helps.

提交回复
热议问题