array_diff() looks for exact duplicates for each value of array 1 in array 2, ignoring the keys.
1has a duplicate in array 2, for example. under the key order. That is why it is not indicated as a difference.
whether this behavior is optimal or obvious is controversial, but how it works.
If you change 1to a 3, this will be reported, since array 2 does not contain a value 3:
$array_1 = [
'id' => '42',
'base_id' => '23',
'role_id' => '3',
'title' => 'Manage Account',
'slug' => 'manage_account',
'parent' => '31',
'order' => '1',
'visibility' => '1'
];
$array_2 = [
'id' => '42',
'base_id' => '23',
'role_id' => '99999',
'title' => 'Manage Account',
'slug' => 'manage_account',
'parent' => '31',
'order' => '1',
'visibility' => '1'
];
var_dump(array_diff($array_1, $array_2));
If you want the keys to be taken into account, use array_diff_assoc().
source
share