Reputation: 3
I have two arrays:
First Array
[
'Test' => 1,
'Test2' => 2,
'Test3' => 3,
...
]
Second Array
[
'0' => 'Test',
'1' => 'SomeTest',
...
]
I want to get difference of first array keys and second array values.
Result Array
[
'Test2' => 2,
'Test3' => 3
]
Upvotes: 0
Views: 40
Reputation: 4261
Use array_flip() and array_diff()
$firstArray = [
'Test' => 1,
'Test2' => 2,
'Test3' => 3
];
$secondArray = [
'0' => 'Test',
'1' => 'SomeTest'
];
$result = array_diff($firstArray, array_flip($secondArray));
print_r($result);
exit;
Upvotes: 1