项目中需要对导入的数据做号码去重,数据格式如下:
核心代码如下:(百度回来的)
// php 数组根据某个值去重
protected function array_unique_by_value($array, $key) {
$unique = array();
foreach ($array as $value) {
if (!array_key_exists($key, $value)) {
throw new InvalidArgumentException('The provided array does not have the specified key');
}
if (!array_key_exists($value[$key], $unique)) {
$unique[$value[$key]] = $value;
}
}
return array_values($unique);
}
实际运用:
实现的效果: