[PHP-DEV] array_diff() failures From: Andrei Zmievski (andrei <email protected>)
Date: 12/28/00

Stig,

I've uncovered cases where array_diff() fails to produce the correct
result. I had two identical arrays (unsorted) and I ran array_diff() on
them, expecting to get an empty array back, but array_diff() did produce
some differences. This stems from the fact that you sort the arrays
yourself in the array_diff() and set the comparison function to
SORT_REGULAR. Since the regular comparison function is
non-deterministic, the arrays might be sorted differently depending on
the original order of the elements.

There are two solutions: either users have to presort their arrays and
specify the comparison functions (sort($foo, SORT_STRING) for example),
or there should be a way to set the comparison function that
array_diff() uses.

Thoughts?

-Andrei

"Music expresses that which can not be said
 and on which it is impossible to be silent."
                         -Victor Hugo

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>