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

Basic PHP Tutorial

Advanced PHP 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 performed through the user-provided callback function. A negative integer, zero, or a positive integer must be returned respectively when the first parameter is considered to be less than, equal to, or greater than the second parameter.
Note: Unlike array_uintersect(), the key names are also compared. The data is compared using a callback function.

Return Value

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

Parameter

Serial NumberParameters and Description
1

array1(Required)

It specifies an array.

2

array2(Required)

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(Required)

Name of the user-defined function.

Online Example

The array_uintersect_assoc function uses the strcasecmp function to compare keys and values, calculating 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