Example 1 — Comparing Keys and Values
Only entries with the same key and the same value are treated as equal.
<?php
$a = ['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red'];
$b = ['a' => 'green', 'yellow', 'red'];
print_r(array_diff_assoc($a, $b)); How It Works
- 'a' => 'green' exists in both arrays with the same key and value, so it is removed.
- The keys 'b' and 'c' do not exist in $b, so they are kept.
- 'red' is at key 0 in $a, but key 0 in $b holds 'yellow', so it is kept.
- 'red' also appears in $b, but at key 1, and the key must match too.

