Example 1 — Comparing Keys With strcmp
Use strcmp as the callback to compare the keys exactly.
<?php
$a = ['blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4];
$b = ['green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8];
print_r(array_diff_ukey($a, $b, 'strcmp')); How It Works
- strcmp returns 0 only when two keys are exactly the same.
- The keys 'blue' and 'green' exist in both arrays, so they are removed.
- The keys 'red' and 'purple' do not exist in $b, so they are kept.
- The values of $b, such as 5 and 6, play no role in the result.

