Posted By

Moridin on 07/22/10


Tagged

array unique multi-dimensional arrayunique


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

osirisinternet


Eliminate Duplicates in Multi-Dimensional Arrays


 / Published in: PHP
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.