note 94009 deleted from function.array-diff by danbrown
| From: | danbrown@php.net | Date: | Tue, 13 Oct 2009 15:44:18 +0000 |
| Subject: | note 94009 deleted from function.array-diff by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161693@lists.php.net to get a copy of this message | ||
Note Submitter: me at fusionstream.org
----
To build on "merlinyoda at dorproject dot net" comment from 28-Mar-2008 06:11.
If you are dealing with associative arrays:
Instead of array_intersect we use array_intersect_assoc and instead of array_diff we use
array_diff_assoc. Looks like a no brainer but this left me stumped for quite a while.
Also note that the order of the arrays when passed to array_merge and array_intersect_assoc are very
important to the result.
<?php
function array_xor ($array_a, $array_b) {
$union_array = array_merge($array_a, $array_b);
$intersect_array = array_intersect_assoc($array_a, $array_b);
return array_diff_assoc($union_array, $intersect_array)
}
?>