Say I have two arrays:
$a = a,b,c;
$b = a,b;
When I compare this array output should be c
.
Omit the common values in both array.
Say I have two arrays:
$a = a,b,c;
$b = a,b;
When I compare this array output should be c
.
Omit the common values in both array.
The quick answer:
array_merge(array_diff($a, $b), array_diff($b, $a));
array-diff($a, $b) will only extract values from $a which are not in $b.
The idea is to merge the differences.
And another way to achieve your goal might be:
function array_unique_merge() {
return array_unique(call_user_func_array('array_merge', func_get_args()));
}
Have a look at the PHP array_diff function.
$a = a,b,c;
$b = a,b;
$c = array_diff($a,$b);
Firstly, that's not valid PHP - but...
$a = array("a","b","c");
$b = array("a","b");
print_r(array_diff($a,$b)); // Array ( [2] => c )
Just to make things more straighforward
$a = array("a","b","c");
$b = array("a","b");
$new_array = array_merge(array_diff($a, $b), array_diff($b, $a));
while (list ($key, $val) = each ($new_array)) {
echo $val;
}