Use array_diff
and array_merge
:
$result = array_merge(array_diff($array1, $array2), array_diff($array2, $array1));
For multiple arrays, combine it with a callback and array_reduce
:
function unique(&$a, $b) {
return $a ? array_merge(array_diff($a, $b), array_diff($b, $a)) : $b;
}
$arrays = array(
array('green', 'red', 'blue'),
array('green', 'yellow', 'red')
);
$result = array_reduce($arrays, 'unique');
3
solved Get uncommon values from two or more arrays