On Tue, 2011-12-13 at 16:15 -0500, Marc Guay wrote:
> Hi folks,
>
> Let's say that I have the following array:
>
> [0]=>
> array(35) {
> ["contact_id"]=>
> string(3) "356"
> ["contact_first_name"]=>
> string(4) "Marc"
> }
> [1]=>
> array(35) {
> ["contact_id"]=>
> string(3) "247"
> ["contact_first_name"]=>
> string(4) "Marc"
> }
> [2]=>
> array(35) {
> ["contact_id"]=>
> string(3) "356"
> ["contact_first_name"]=>
> string(4) "Marc"
> }
>
> And I would like to filter out exact duplicates, such as key 0 and key
> 2 in this example, leaving me with an array containing only unique
> entries. How would you go about it?
>
> Thanks for any help,
> Marc
>
If I knew exactly what each sub-array were to contain (with regards to
keys) and it was small enough, I could compare those. For your example,
I would imagine just looping through and comparing the contact_id value,
as that seems to be what you'd consider the primary key in database
terms. If the array elements were a bit more unknown, and you needed to
check for exact duplicates, because for example, the forename
(contact_first_name) changed, then you could serialise the array
elements and then compare those. I don't know if serialising the arrays
in this context would alter if the natural index of an array differed
though without testing (and I'm too lazy to do that for you ;-p )
--
Thanks,
Ash
http://www.ashleysheridan.co.uk