Re: Removing duplicates in multi-dimensional array
| From: | Jonathan Sharp | Date: | Thu, 14 Nov 2002 21:18:52 +0000 |
| Subject: | Re: Removing duplicates in multi-dimensional array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-124499@lists.php.net to get a copy of this message | ||
When you build your 2d array you could make a seperate 1d array that's
indexed by the fax number and if it's set, not set it in your array...
-js
René Fournier wrote:
> I'm finding this one hard to approach...
>
> I have a two-dimensional array, containing customer contact information.
> Looks like:
>
> $myarray[0][0] = "Microsoft";
> $myarray[0][1] = "Bill";
> $myarray[0][2] = "123-1234";
>
> $myarray[1][0] = "Apple";
> $myarray[1][1] = "Steve";
> $myarray[1][2] = "456-1234"; <<<<<
>
> $myarray[2][0] = "Oracle";
> $myarray[2][1] = "Larry";
> $myarray[2][2] = "987-4321";
>
> $myarray[3][0] = "Pixar";
> $myarray[3][1] = "Steve";
> $myarray[3][2] = "456-1234"; <<<<<
>
> What I want to do is remove records that have the same fax number, so
> that each fax number occurs only once. For example, $myarray[1][2] and
> $myarray[3][2] are the same--I would like to remove/unset one of them.
>
> I know that array_unique() will do this for one-dimensional arrays, but
> I'm kinda stuck here, since the repeating element is in the second
> dimension. Any ideas how I might do this?
>
> Thanks.
>
> ....Rene
>
> ---
> René Fournier,
> rene@smartslitters.com
>
> Toll-free +1.888.886.2754
> Tel +1.403.291.3601
> Fax +1.403.250.5228
> www.smartslitters.com
>
> SmartSlitters International
> #33, 1339 - 40th Ave NE
> Calgary AB T2E 8N6
> Canada
>
>