Re: array_diff() failures
| From: | Stig Venaas | Date: | Fri, 29 Dec 2000 00:14:11 +0000 |
| Subject: | Re: array_diff() failures | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-42490@lists.php.net to get a copy of this message | ||
Hi again
On Thu, Dec 28, 2000 at 07:58:40PM +0100, Stig Venaas wrote:
> Hi
>
> On Thu, Dec 28, 2000 at 11:42:22AM -0600, Andrei Zmievski wrote:
> > 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.
I've now removed array_type_data_compare and am using array_data_compare
with SORT_STRING. Seems to work well. Thanks for bringing this to my
attention. If you think there still are problems, let me know. There
were similar problems with array_unique() and array_intersect(), they
should also be okay now.
I don't like how SORT_REGULAR works and the fact that one can get
segfaults on Solaris with sort() etc. but I guess it's a bit drastic
to change it. Perhaps avoid the systems qsort when using SORT_REGULAR?
What do you think?
Stig