$arr = array( 25 =>array( ‘mid‘ => ‘28838‘, ‘invest_money‘ => ‘1196000‘, ‘rm_id‘ => ‘157733‘, ),
27 =>array ( ‘mid‘ => ‘28838‘, ‘invest_money‘ =>‘1180000‘, ‘rm_id‘ => ‘157733‘,),
28 => array ( ‘mid‘ => ‘28838‘, ‘invest_money‘ => ‘910000‘, ‘rm_id‘ => ‘157733‘,),
2205 => array(‘mid‘ =>‘20191‘, ‘invest_money‘ => ‘350000‘, ‘rm_id‘ => ‘157733‘, ),
2207 => array ( ‘mid‘ => ‘20191‘, ‘invest_money‘ => ‘550000‘, ‘rm_id‘ => ‘157733‘,) );
$arr = array_values($arr);
$new = array();
foreach($arr as $key=>$val) {
if($key == 0) {
$new[$val[‘mid‘]] = $val[‘invest_money‘];
} else {
if(array_key_exists($val[‘mid‘], $new)) {
$new[$val[‘mid‘]] += $val[‘invest_money‘];
} else {
$new[$val[‘mid‘]] = $val[‘invest_money‘];
}
}
}
$new2 = array();
foreach($arr as $key=>$val) {
foreach($new as $k=>$v) {
if($arr[$key][‘mid‘] == $k) {
$new2[$k][‘mid‘] = $k;
$new2[$k][‘invest_money‘] = $v;
$new2[$k][‘rm_id‘] = $val[‘rm_id‘];
}
}
}
array
28838 =>
array
‘mid‘ => 28838
‘invest_money‘ => 3286000
‘rm_id‘ => ‘157733‘
20191 =>
array
‘mid‘ => 20191
‘invest_money‘ => 900000
‘rm_id‘ => ‘157733‘