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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_uintersect() function usage and example

PHP Array Function Manual

The array_uintersect() function calculates the intersection of arrays using a callback function to compare data

Syntax

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

Definition and usage

array_uintersect() returns an array that contains all the elements in array1 values that also appear in all other parameter arrays. Data comparison is done using a callback function. This comparison is done through the callback function provided by the user. 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.

Return value

This function returns an array containing all array1All values. Use callback function to compare data.

Parameter

Serial numberParameters and descriptions
1

array1

Need. Specify an array.

2

array2

Need. Specify the array to be compared with the first array.

3

array3

Optional. Specify the array to be compared with the first array.

4

data_compare_func

Need. The name of the user-defined function.

Online example

Use the built-in function strcasecmp as the callback function to calculate the intersection of two arrays

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

Output result:

Array ( [a] => green [b] => brown [0] => red )

PHP Array Function Manual