直接上代码
//二维数组去重
$data = array(
0 => array(‘num‘ => ‘110‘, ‘name‘ => ‘nick1‘),
1 => array(‘num‘ => ‘111‘, ‘name‘ => ‘nick2‘),
2 => array(‘num‘ => ‘110‘, ‘name‘ => ‘nick3‘),
3 => array(‘num‘ => ‘112‘, ‘name‘ => ‘nick4‘),
4 => array(‘num‘ => ‘113‘, ‘name‘ => ‘nick5‘),
5 => array(‘num‘ => ‘113‘, ‘name‘ => ‘nick6‘)
);
foreach ($data as $val) {
$temp[] = $val[‘num‘];
}
$temp = array_unique($temp); // array_unique 去重后键值不变
foreach ($temp as $key => $value) {
$needData[] = $data[$key];
}
var_dump($needData);exit;
运行结果:
时间: 2024-10-16 21:20:47