Created
March 1, 2014 13:29
-
-
Save albabar/9289787 to your computer and use it in GitHub Desktop.
Remove duplicate arrays from a 2D array. Takes an input 2D array and returns a new 2D array without duplicate arrays.
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 unique_array($multidimetionalarray) { | |
$static_array = array(); | |
foreach($multidimetionalarray as $array){ | |
$static_array[] = json_encode($array); | |
} | |
$filtered_static_array = array_unique($static_array); | |
$filtered_array = array(); | |
foreach($filtered_static_array as $array){ | |
$filtered_array[] = json_decode($array, true); | |
} | |
return $filtered_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better use
array_unique($array, SORT_REGULAR)
which generate same result with less effort.