RE: [PHP] removing all duplicate values from an array
| From: | Mike Migurski | Date: | Thu, 30 Oct 2003 22:14:58 +0000 |
| Subject: | RE: [PHP] removing all duplicate values from an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-168189@lists.php.net to get a copy of this message | ||
>array(
>'a' => 'one',
>'b' => 'one',
>'c' => 'zero',
>'d' => 'two'
>);
>
>through this and am having a hind time with then logic... Could you
>explain how the output would be array('c' => 'zero', 'd' =>
>'two')??
I was being pretty sloppy with the code (should've posted pseudocode to
begin with, my bad) but the general logic is: cycle through each element
of the input array. If the value has not been encountered before, store
the value and key in a secondary array. If the value has been encountered
before (it's present in the secondary array), remove it from the input
array, and use the the stored key/value in the secondary array to unset
its first instance in the input array, too.
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html