PHP array_intersect_uassoc() Function

PHP array_intersect_uassoc Function


Definition :

The array_intersect_uassoc() function compares the values of two or more arrays and returns the matches with additional key check using a user-defined key comparison function.

Note: This function uses a user-defined function to compare the keys!

This function compares the keys and values of two or more arrays, and return an array that contains the entries from array1 that are present in array2array3, etc.

Syntax:

The basic syntax of the array_intersect_uassoc() function is given with:

  array_intersect_uassoc(array1array2...key_compare_function);

Parameters:

The array_intersect_uassoc() function accepts the following parameters.

Parameter Description
array1 Required. Specifies the array to compare from.
array2 Required. Specifies an array to compare against.
... Optional. Specifies more arrays to compare against.
key_compare_function Required. Specifies a callback function to use for key comparison.

Example1 :

The following example shows the array_intersect_uassoc()(using a user-defined key comparison function) function in action.

Output :

Array
(
    [b] => designing
)

Example2 :

Compare the keys and values of three arrays (use a user-defined function to compare the keys), and return the matches:

Output :

Array
(
    [a] => web
)