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 Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php