array_uintersect(array $array1, array $array2, callable $callback): array
function caseInsensitiveCompare($a, $b) {
return strcmp(strtolower($a), strtolower($b));
}
$array1 = ['APPLE', 'BANANA', 'CHERRY'];
$array2 = ['apple', 'ORANGE', 'cherry'];
$result = array_uintersect($array1, $array2, 'caseInsensitiveCompare');
print_r($result);
Output
Array
(
[0] => APPLE
[2] => CHERRY
)
function numCompare($a, $b) {
return $a - $b;
}
$array1 = [1, 2, 3, 4];
$array2 = [3, 4, 5, 6];
$result = array_uintersect($array1, $array2, 'numCompare');
print_r($result);
Output
Array
(
[2] => 3
[3] => 4
)
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.