PHP computing two-dimensional array of the specified element

array_sum(array_column($arr, 'num'));
// calculate the two-dimensional array of the specified element 
$ ARR = [ 
    [
         'ID' =>. 1, 
        'NUM' =>. 3, 
    ] , 
    [
         'ID' => 2, 
        'NUM' =>. 4, 
    ] , 
    [
         ' ID '=>. 3, 
        ' NUM '=>. 1, 
    ] , 
]; 
// calculate the two-dimensional array of the specified element 
$ ARR = array_sum (array_column ( $ ARR ,' NUM ')); // output. 8 
var_dump ( $ arr );

 

Guess you like

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