Re: [PHP] removing all duplicate values from an array
From: Allowee (Vincent_at_GeversXL.nl)
Date: 10/30/03
- Next message: Jeremy Russell: "RE: [PHP] removing all duplicate values from an array"
- Previous message: Gareth Williams: "Object References Problem"
- In reply to: Mike Migurski: "Re: [PHP] removing all duplicate values from an array"
- Next in thread: Kevin Stone: "RE: [PHP] removing all duplicate values from an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: Mike Migurski <mike@saturn5.com> Date: Thu, 30 Oct 2003 22:54:44 +0100
On Thursday 30 October 2003 20:37, Mike Migurski wrote:
> >>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;
> }
Hi,
I edited it a bit to match my script and after some tweaks of my own code it
started working :)
Thanks,
Allowee
>
>
> ---------------------------------------------------------------------
> michal migurski- contact info and pgp key:
> sf/ca http://mike.teczno.com/contact.html
- Next message: Jeremy Russell: "RE: [PHP] removing all duplicate values from an array"
- Previous message: Gareth Williams: "Object References Problem"
- In reply to: Mike Migurski: "Re: [PHP] removing all duplicate values from an array"
- Next in thread: Kevin Stone: "RE: [PHP] removing all duplicate values from an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|