日期:2014-05-17 浏览次数:20484 次
<?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 "<pre>";
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;