So the docs are right?

Note that keys are preserved. array_unique() sorts the values treated as
string at first, then will keep the first key encountered for every value,
and ignore all following keys. It does not mean that the key of the first
related value from the unsorted array will be kept.

Best regards
Andrey Hristov


----- Original Message -----
From: "Stig Venaas" <[EMAIL PROTECTED]>
To: "Andrey Hristov" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, September 03, 2002 11:16 AM
Subject: [PHP-QA] Re: [PHP-DEV] Re: [PHP-QA] array_unique broken?


> On Tue, Sep 03, 2002 at 11:04:55AM +0300, Andrey Hristov wrote:
> > Hi,
> > I am not too much in array_unique() but played with array_diff() for a
week
> > to implement array_diff_assoc() with no success so far but atm I am
dreaming
> > the code of array_diff. I
> > saw that most of the code of array_diff() is in array_intersect() and
> > probably in array_unique() (yup it is like them).
> > The argument is sorted with zend_qsort() by value and nothing is known
for
> > the key order in the
> > sorted array. Then the array is traversed from the beginning to the end
and
> > when two or more sequental elements are equal everything starting the
second
> > equal is wiped (in the result that is returned).
>
> The new code in CVS for array_unique() does actually (or should) always
> keep the first element.
>
> This was accidentally the case, at least on some platforms, before
> zend_qsort() was introduced because some native qsort() implementations
> use mergesort (at least on small datasets) which preserves the order.
>
> Stig
>
> --
> PHP Quality Assurance Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to