Skip to content

Instantly share code, notes, and snippets.

@intellix
Created July 28, 2013 13:40
Show Gist options
  • Save intellix/6098619 to your computer and use it in GitHub Desktop.
Save intellix/6098619 to your computer and use it in GitHub Desktop.
Multi Dimensional array_unique
/**
* 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