[Solved] Get uncommon values from two or more arrays


Use array_diff and array_merge:

$result = array_merge(array_diff($array1, $array2), array_diff($array2, $array1));

Here’s a demo.

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');

And here’s a demo of that.

3

solved Get uncommon values from two or more arrays