I have two arrays with data in them and I need to compare the two and return the array that are not matched.
I have two arrays that both look like this:
$arr1 = array(
array('name' => 'Alan', 'age' => '34', 'country' => 'usa'),
array('name' => 'James', 'age' => '24', 'country' => 'spain' ),
);
$arr2 = array(
array('name' => 'Alan', 'age' => '34', 'country' => 'usa'),
array('name' => 'James', 'age' => '54', 'country' => 'spffain' ),
);
i would like comparing the array by name,age and country and return me the array that are not matched.
my code so far:
$intersect = array_uintersect($arr1, $arr2, 'compareDeepValue');
echo "<pre>", print_r($intersect);
function compareDeepValue($val1, $val2)
{
return strcmp($val1['age'], $val2['age']);
return strcmp($val1['country'], $val2['country']);
return strcmp($val1['name'], $val2['name']);
}
The code above return the array that are matched. How can i changed the code in order to get the array that are not matched?
EXPECTED OUTPUT:
Array
(
[0] => Array
(
[name] => James
[age] => 21
[country] => spain
)
)
compareDeepValuehas 3 return statements. Only first is reachreachable.