将二维数组中 相同 time和id 值的num累计
<?php $res = [ 0=>[ 'time'=>'2021-06-02', 'id'=>'122', 'num'=>1 ], 1=>[ 'time'=>'2021-06-03', 'id'=>'121', 'num'=>2 ], 2=>[ 'time'=>'2021-06-03', 'id'=>'121', 'num'=>3 ], ]; foreach($res as $k=>$v){ if(!isset($ret[$v['time'].'_'.$v['id']])){ $ret[$v['time'].'_'.$v['id']] = $v; }else{ $ret[$v['time'].'_'.$v['id']]['num'] += $v['num']; } } print_r($ret); ?>
标签:06,ret,二维,num,2021,数组,time,id,总和 From: https://www.cnblogs.com/we-jack/p/17265848.html