Re: removing all duplicate values from an array

From: Date: Thu, 30 Oct 2003 19:37:10 +0000
Subject: Re: removing all duplicate values from an array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-168172@lists.php.net to get a copy of this message
>>I'm looking for a function that does almost the same as array_unique() >> >>But it must also delete the other duplicate entry. ><snip> > >Untested pseudo-PHP follows - > > $encountered_elements = array(); > foreach($original_array as $key => $val) > if(in_array($val, $encountered_elements)) { > unset($original_array[$key]); > } else { > $encountered_elements[$key] = $val; > } Oops, that should have been: $encountered_elements = array(); foreach($original_array as $key => $val) if(in_array($val, $encountered_elements)) { unset($original_array[$encountered_elements[$val]]); } else { $encountered_elements[$val] = $key; } --------------------------------------------------------------------- michal migurski- contact info and pgp key: sf/ca http://mike.teczno.com/contact.html

« previous php.general (#168172) next »