Last active
July 12, 2019 06:19
-
-
Save haxianhe/4aa229c5c5ce2e1757d90b2564b5740c to your computer and use it in GitHub Desktop.
php 二维数组去掉重复值
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? php | |
/** | |
* 对二维数组去重 | |
* @param $array2D | |
* @return array | |
*/ | |
function unique_array_more($array2D) | |
{ | |
foreach ($array2D[0] as $key => $value) { | |
$keys[] = $key; | |
} | |
foreach ($array2D as $key => $value) { | |
$str = join(",", $value); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串 | |
$array1D[] = $str; | |
} | |
$array1D = array_unique($array1D); //去掉重复的字符串,也就是重复的一维数组 | |
foreach ($array1D as $key => $value) { | |
$new = explode(",", $value); //再将拆开的数组重新组装 | |
$uniqueArray2D[$key]=array_combine($keys,$new); | |
} | |
return $uniqueArray2D; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update