php二维数组相同id的数量相加
数组样式
$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, ), );
处理办法
$item=array(); 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);