php 合并一个二维数组相同项,数量则相加 $arr = array( array( 'user_id' => 100, 'goods_id' => 10, 'number' => 1, ), array( 'user_id' => 100, 'goods_id' => 10, 'number' => 2, ), array( 'user_id' => 100, 'goods_id' => 10, 'number' => 2, ), array( 'user_id' => 100, 'goods_id' => 10, 'number' => 2, ), ); 理想结果: $arr = array( array( 'user_id'=> 100, 'goods_id' => 10, 'number' => 7, ), ); foreach($arr as $k=>$v){ if(!isset($item[$v['user_id']])){ $item[$v['user_id']]=$v; }else{ $item[$v['user_id']]['number']+=$v['number']; } } print_r($item);