Created
December 18, 2017 23:21
-
-
Save sinau123/e5f3f4460dbb99efc6c3dc3ab7d44972 to your computer and use it in GitHub Desktop.
array unique on multidimensional array
This file contains 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 | |
function arr_unique($arr, $index){ | |
$tmpArray = []; | |
$newArray =[]; | |
foreach ($arr as $val) { | |
if(!in_array($val[$index],$tmpArray)) { | |
$newArray[]=$val; | |
$tmpArray[]=$val[$index]; | |
} | |
} | |
return $newArray; | |
} | |
$arr=[ | |
[1,2,3], | |
[2,3,4], | |
[1,3,4], | |
[2,4,5] | |
]; | |
print_r(arr_unique(array_reverse($arr),0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment