PHP gets the specified field values of two-dimensional arrays and

array_sum(array_column($arr, 'num'));

// Get field and two-dimensional array num 
$ ARR = [ 
[
     'device_uid' => '123456', 
    'num' => '. 5', 
] , 
[
     'device_uid' => '123457', 
    'num' => '2', 
] , 
[
     'device_uid' => '123 458', 
    'NUM' => '. 4', 
] , 
]; 
echo '<pre>' ;
 // after the first two-dimensional array processing, re-processing summing array 
$ ARR = array_sum (array_column ( $ ARR , 'NUM' ));
 var_dump ( $ ARR );

 

Guess you like

Origin www.cnblogs.com/camg/p/11980176.html