function unique($data = array()){ $tmp = array(); foreach($data as $key => $value){ //把一维数组键值与键名组合 foreach($value as $key1 => $value1){ $value[$key1] = $key1 . '_|_' . $value1;//_|_分隔符复杂点以免冲突 } $tmp[$key] = implode(',|,', $value);//,|,分隔符复杂点以免冲突 } //对降维后的数组去重复处理 $tmp = array_unique($tmp); //重组二维数组 $newArr = array(); foreach($tmp as $k => $tmp_v){ $tmp_v2 = explode(',|,', $tmp_v); foreach($tmp_v2 as $k2 => $v2){ $v2 = explode('_|_', $v2); $tmp_v3[$v2[0]] = $v2[1]; } $newArr[$k] = $tmp_v3; } return $newArr; } //测试 $data = array( array('id'=>1, 'title'=>'元芳', 'score'=>10), array('id'=>2, 'title'=>'元芳,你怎么看', 'score'=>10), array('id'=>3, 'title'=>'大人说:元芳,你怎么看', 'score'=>9), array('id'=>1, 'title'=>'元芳', 'score'=>10), ); $newArr = unique($data); //去重复后的二维数组 Array ( [0] => Array ( [id] => 1 [title] => 元芳 [score] => 10 ) [1] => Array ( [id] => 2 [title] => 元芳,你怎么看 [score] => 10 ) [2] => Array ( [id] => 3 [title] => 大人说:元芳,你怎么看 [score] => 9 ) )
非常好使