二位数组多字段去重
不指定一个字段去重,判断所有字段是否有重复
$arr = [ 0 => [ ‘name‘ => ‘name1‘, ‘age‘ => ‘10‘ ], 1 => [ ‘name‘ => ‘name1‘, ‘age‘ => ‘11‘ ], 2 => [ ‘name‘ => ‘name2‘, ‘age‘ => ‘10‘ ], 3 => [ ‘name‘ => ‘name2‘, ‘age‘ => ‘10‘ ] ];
方法:
$res = []; foreach ($arr as $key => $value) { //重新排序value ksort($value); //获取key ,判断是否存在的依据 $key = implode("_", $value); //name1_10 //md5 为了防止字段内容过长特殊字符等 $res[md5($key)] = $value; } //重置索引 $res = array_values($res); var_dump($res);
原文地址:https://www.cnblogs.com/inkwhite/p/12222690.html
时间: 2024-10-10 22:38:08