Eliminate Duplicates in Multi-Dimensional Arrays


/ Published in: PHP

Courtesy of Dorphalsig on php.net (see URL above)


Copy this code and paste it in your HTML
  1. // remove duplicate elements from n-dimensional arrays
  2. function uniqueArray($nDimArray) {
  3.  
  4. foreach($nDimArray as &$val) {
  5. $val = serialize($val);
  6. }
  7. $nDimArray = array_unique($nDimArray);
  8. foreach($nDimArray as &$val) {
  9. $val = unserialize($val);
  10. }
  11. return $nDimArray;
  12. }

URL: http://www.php.net/manual/en/function.array-unique.php#84750

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.