Re: Re: array_unique broken?
| From: | Stig Venaas | Date: | Tue, 03 Sep 2002 08:16:50 +0000 |
| Subject: | Re: Re: array_unique broken? | ||
| References: | 1 2 | Groups: | php.dev php.qa |
| Request: | Send a blank email to php-dev+get-87851@lists.php.net to get a copy of this message | ||
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