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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_uintersect_assoc() function usage and example

PHP Array Function Manual

The array_uintersect_assoc() function calculates the intersection of arrays with index checking, using a callback function to compare data

Syntax

array_uintersect_assoc( $array1, $array2 [, $array3 ..., $data_compare_func] );

Definition and Usage

 This comparison is made through the user-provided callback function. You must return an integer less than, equal to, or greater than zero if you think the first parameter is less than, equal to, or greater than the second parameter.
Note that unlike array_uintersect(), the key name is also compared. The data is compared using a callback function.

Return value

 Returns an array that contains all the values that appear in the array1 The value also appears in all other parameter arrays. 

Parameter

NumberParameters and Description
1

array1(mandatory)

It specifies an array.

2

array2(mandatory)

It specifies the array to be compared with the first array.

3

array3(optional)

It specifies the array to be compared with the first array.

4

data_compare_func(mandatory)

Name of the user-defined function.

Online example

array_uintersect_assoc uses the strcasecmp function to compare keys and values, and calculates the intersection of arrays

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

Output result:

Array ( [a] => green )

   PHP Array Function Manual