Try this: You can diffirentiate there keys because after your array are keys of arrays
$newArr = [
['a' => 'b', 'c' => 'x'],
['a' => 'c', 'c' => 'x']
];
$a = array_diff_assoc($newArr[0], $newArr[1]); //differentiate the 1st and 2nd keys
$b = array_diff_assoc($newArr[1], $newArr[0]); //differentiate the 2nd keys to the 1st keys
$diff = [$a, $b]; //then store the result to an array
echo '<pre>';
var_dump($diff);
Here's the output:
array(2) {
[0]=>
array(1) {
["a"]=>
string(1) "b"
}
[1]=>
array(1) {
["a"]=>
string(1) "c"
}
}
Or if it is a array of array:
//all keys are 0 and 1 because you're differentiate only two keys in one multi-dimensional array
$arr2= [
0 => [
['a' => 'b', 'c' => 'x'],
['a' => 'c', 'c' => 'x']
],
1 => [
['d' => 'e', 'c' => 'y'],
['d' => 'b', 'c' => 'y']
]
];
foreach($arr2 as $key => $val){
$a[] = array_diff_assoc($val[0], $val[1]);
$b[] = array_diff_assoc($val[1], $val[0]);
}
var_dump($diff);
Output:
array(2) {
[0]=>
array(2) {
[0]=>
array(1) {
["a"]=>
string(1) "b"
}
[1]=>
array(1) {
["d"]=>
string(1) "e"
}
}
[1]=>
array(2) {
[0]=>
array(1) {
["a"]=>
string(1) "c"
}
[1]=>
array(1) {
["d"]=>
string(1) "b"
}
}
}