日期:2014-05-17 浏览次数:20447 次
$array = array( array('pid'=>1,'name'=>'a'), array('pid'=>2,'name'=>'b'), array('pid'=>3,'name'=>'c'), array('pid'=>1,'name'=>'a') ); $tmp=array(); foreach($array as $k=>$v){ if(!$tem[$v[pid].'_'.$v[name]]){ $tem[$v[pid].'_'.$v[name]]=$v; print_r($v); }else{ exit; } }
------解决方案--------------------
$array = array( array('pid' => 1, 'name' => 'a'), array('pid' => 2, 'name' => 'b'), array('pid' => 3, 'name' => 'c'), array('pid' => 4, 'name' => 'd'), array('pid' => 5, 'name' => 'e'), array('pid' => 1, 'name' => 'a'), array('pid' => 4, 'name' => 'd') ); $idList = array(); foreach ($array as $key => $value) { $idList[] = implode(',', $value); } $idList2 = array_diff_assoc($idList, array_unique($idList)); foreach ($idList2 as $key => $value) { $akey = array_search($value, $idList); echo '重复数组:'; print_r($array[$akey]); }