Created
July 28, 2013 13:40
-
-
Save intellix/6098619 to your computer and use it in GitHub Desktop.
Multi Dimensional array_unique
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
/** | |
* Removes duplicate entries in a multi-dimensional array | |
* @param array $a the array you want to process | |
* @param string $i the index you would like to run against | |
* @return array the processed array | |
*/ | |
public function md_array_unique($a, $i) { | |
$unset = array(); | |
for($x = 0; $x < sizeof($a); $x++){ | |
for($y = 1; $y < (sizeof($a) - $x); $y++){ | |
if ($a[$x][$i] == $a[($x+$y)][$i]){ | |
$unset[] = ($x+$y); | |
} | |
} | |
} | |
foreach($unset as $key){ | |
unset($a[$key]); | |
} | |
return $a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment