NYCPHP Meetup

NYPHP.org

[nycphp-talk] what's up with array_diff()

David Mintz david at davidmintz.org
Wed Sep 19 16:34:59 EDT 2007


The description of array_diff at
http://www.php.net/manual/en/function.array-diff.php says it computes the
difference between the arrays you pass it, and returns that difference as an
array.

The behavior is that it finds and returns an array of elements that are
present in the first argument that are not present in the following
arguments, so the order in which you pass in your arrays is all-important.

I am trying to find out if two arrays are different from each other or not.
I can sort() and then compare with ==, but I thought this might be more
elegant.

Now I am looking at

       if (array_diff($one,$two) or array_diff($two,$one)) {
           /* do something */
       }

but I wonder if anyone can suggest a better way.

Thanks.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070919/c320d5c1/attachment.html>


More information about the talk mailing list