Skip to content

Instantly share code, notes, and snippets.

@sinau123
Created December 18, 2017 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinau123/e5f3f4460dbb99efc6c3dc3ab7d44972 to your computer and use it in GitHub Desktop.
Save sinau123/e5f3f4460dbb99efc6c3dc3ab7d44972 to your computer and use it in GitHub Desktop.
array unique on multidimensional array
<?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