array_sum(array_column($arr, ‘num‘));
//计算二维数组指定元素的和 $arr = [ [ ‘id‘=>1, ‘num‘=>3, ], [ ‘id‘=>2, ‘num‘=>4, ], [ ‘id‘=>3, ‘num‘=>1, ], ]; //计算二维数组指定元素的和 $arr = array_sum(array_column($arr, ‘num‘));//输出8 var_dump($arr);
原文地址:https://www.cnblogs.com/camg/p/11986608.html
时间: 2024-10-01 10:59:21