Example 1 — Case-Insensitive Keys
Use strcasecmp so that Red and red count as the same key.
<?php
$a = ["Red" => "apple", "Green" => "leaf", "Blue" => "sky"];
$b = ["red" => "apple", "green" => "grass", "blue" => "sky"];
$result = array_intersect_uassoc($a, $b, "strcasecmp");
echo json_encode($result), PHP_EOL; How It Works
- Build two arrays. The keys differ only by letter case.
- Pass strcasecmp. It tells PHP to treat
Redandredas equal keys. - Check values too.
Greenis dropped becauseleafis notgrass. - Read the result. Only
RedandBluematch on both key and value.

