Re: [PHP] removing all duplicate values from an array

From: Allowee (Vincent_at_GeversXL.nl)
Date: 10/30/03


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



Relevant Pages

  • Re: Iframe - does google index inframes ?
    ... using GPG (oops) to encrypt your sensitive data on your Ubuntu ... and upload it to your GDrive account:-D. ... As for Ubuntu, shame on Connonical. ... Elating script kiddies to script Gods (script: ...
    (alt.internet.search-engines)
  • Re: oops in 2.6.14-rc3 (pcmcia i82365 patch)
    ... > kernel 2.6.14-rc3 I noted this oops when shutting down the machine. ... That driver is loaded in rc.pcmcia script during boot and usually ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Loss of SQL behind views again...oops..:)
    ... MVP - Technologies Virtual-PC ... > oops, pushed send a bit early before, been a long day! ... > long script behind them. ... > The problem I am getting is occasionally when the view is opened in design ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Governemnt contract to Alan Sugar-just co-incidence of course.
    ... Oops, I'm talking bollocks again... ... So I looked at the script ... It was six weeks filming in the desert. ...
    (uk.politics.misc)
  • Loss of SQL behind views again...oops..:)
    ... oops, pushed send a bit early before, been a long day! ... I am having a weird problem with SQL server 7.0 and Access 2000. ... long script behind them. ... The problem I am getting is occasionally when the view is opened in design ...
    (microsoft.public.access.adp.sqlserver)