PHP array_intersect_uassoc() function

Last Updated: February 12, 2022

array_intersect_key : Computes the intersection of arrays using keys for comparison. This function uses a callback function to do the comparison.

Syntax

 array_intersect_uassoc(array $array, array ...$arrays, callable $key_compare_func): array

Supports (PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
array Required. array with values to check intersected values
arrays Required. arrays to be compared with the first array
key_compare_func Required. Callable function callback(mixed $a, mixed $b): int

Return Value

Return an array containing elements that are also appearing in other arrays

Example

<?php
$array1 = array("1" => "one", "2" => "two", "3" => "three", "four");
$array2 = array("1" => "One", "3" => "three", "four", "five");
print_r(array_intersect_uassoc($array1, $array2, "strcasecmp"));
?>

Output

Array ( [3] => three [4] => four ) 
Test