Example 1 — Case-Insensitive Difference
Find fruit names that are not in the second list, ignoring upper and lower case.
<?php
$a = ["Apple", "Banana", "Cherry"];
$b = ["apple", "cherry"];
$diff = array_udiff($a, $b, fn($x, $y) => strcasecmp($x, $y));
echo implode(", ", $diff), PHP_EOL; How It Works
- The first array has three fruits and the second has two in lowercase.
- strcasecmp() compares two strings and ignores case.
- "Apple" matches "apple" and "Cherry" matches "cherry", so both are removed.
- Only "Banana" is left, and implode() prints it.

