array_sum(array_column($arr, ‘num‘));
//获取二维数组 num字段的和 $arr = [ [ ‘device_uid‘ => ‘123456‘, ‘num‘ => ‘5‘, ], [ ‘device_uid‘ => ‘123457‘, ‘num‘ => ‘2‘, ], [ ‘device_uid‘ => ‘123458‘, ‘num‘ => ‘4‘, ], ]; echo ‘<pre>‘; //先对二维数组进行处理,再对处理后的数组求和 $arr = array_sum(array_column($arr, ‘num‘)); var_dump($arr);
原文地址:https://www.cnblogs.com/camg/p/11980176.html
时间: 2024-11-05 14:57:16