array_diff() failures

From: Date: Thu, 28 Dec 2000 17:42:22 +0000
Subject: array_diff() failures
Groups: php.dev 
Request: Send a blank email to php-dev+get-42448@lists.php.net to get a copy of this message
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

« previous php.dev (#42448) next »