php 统计二维数组中某个相等值的总个数,并且组合成一个新的数组比如这样的,我想将这个数组里面 m_id 相等数组元素再组合成一个新的数组:效果图如下: php? 多维数组? 分享到: ------解决方案--------------------$arr=array( array( 'sv_id'=>1, 'm_id'=>1, 'sv_question1'=>20 ), array( 'sv_id'=>2, 'm_id'=>2, 'sv_question1'=>10 ), array( 'sv_id'=>3, 'm_id'=>1, 'sv_question1'=>20 ), array( 'sv_id'=>4, 'm_id'=>3, 'sv_question1'=>20 ), array( 'sv_id'=>5, 'm_id'=>2, 'sv_question1'=>10 ) );//var_dump($arr);$ar=array();foreach($arr as $v){ if(empty($ar) ------解决方案-------------------- !in_array($v,$ar)){ $ar[$v['m_id']][$v['sv_id']]=$v; }else{ foreach($ar as $ka=>$va){ if($ka==$v['m_id']){ $ar[$ka][$v['sv_id']]=$v; } } }}echo "";var_dump($ar);你复制运行一下看是不是你要的效果。效果图:------解决方案--------------------不考虑你多出的项目(我无法臆造)$ar = array( array( 'sv_id' => 1, 'mid' => 1, 'sv_question1' => 20 ), array( 'sv_id' => 2, 'mid' => 2, 'sv_question1' => 10 ), array( 'sv_id' => 3, 'mid' => 1, 'sv_question1' => 20 ), array( 'sv_id' => 4, 'mid' => 3, 'sv_question1' => 20 ), array( 'sv_id' => 5, 'mid' => 2, 'sv_question1' => 20 ),);$res = array();foreach($ar as $item) { $res[$item['mid']][$item['sv_id']] = $item;