English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_intersect_uassoc() Function Usage and Example

PHP Array Function Manual

 The PHP array_intersect_uassoc() function uses a user-defined callback function to calculate the intersection of arrays, using the callback function to compare indices.

Syntax

array_intersect_uassoc($array1, $array2 , $array3 ..., callback $key_compare_func] );

Definition and Usage

array_intersect_uassoc() returns an array that contains all values that appear in all the array1 also appear in all other parameter arrays. The key names in the returned array remain unchanged.
Note that unlike array_intersect(), it also compares key names in addition to key values.
This comparison is made through the callback function provided by the user. The function takes two parameters, which are the two key names to be compared. If the first parameter is less than the second parameter, the function should return a negative number, if the two parameters are equal, it should return 0, and if the first parameter is greater than the second parameter, it should return a positive number.

Parameter

Serial NumberParameters and Description
1

array1(Required)

The first array is the array that other arrays will be compared with.

2

array2(Required)

This is the array to be compared with the first array

3

array3(Optional)

This is the array to be compared with the first array

4

key_compare_func(Required)

User-defined callback function.

Return Value

Returns an array that contains all values that appear in all the array1 also appear in all other parameter arrays. The key names in the returned array remain unchanged.

Online Example

How to assign multiple arrays to a function:

<?php
   $input1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
   $input2 = array("a" => "GREEN", "B" => "brown", "yellow", "RED");
   
   $result = array_intersect_uassoc($input1, $input2, "strcasecmp");
   print_r($result);
?>
Test and see‹/›

Output Result:

Array ( [b] => brown )

PHP Array Function Manual