array_uintersect ($array1, $array2, $array3, ..... $arrayn, user_functionParameters :this function takes two types of parameters. One - is a list of arrays and the other is - a user-defined function.
- a list of arrays: this function takes a space-separated list of arrays that we want to find an intersection for. In the above syntax, a list of arrays: $array1, $array2, $array3,… .. $arrayn. It can take any the number of space-separated arrays with a minimum value of 2.
- user_function:is a string type parameter that is the name of a user-defined function. The function returns 0 if the values in its parameter are the same, returns 1 if the first parameter is greater than the second, otherwise it returns -1.
Input: $a1 = array ("a" = > "striver", "b" = > "engineer", "d" = > "raj") $a2 = array ("d" = > "articles", "e" = > "raj", "f" = > "coding") Output : Array ([d] = > raj) Input: $a1 = array ("1" = > "engineer", "2" = > "for", "3" = > "geek", "4 "= >" coding ") $a2 = array (" 1 "= >" engineer "," 2 "= >" for "," 3 "= >" php "," 4 "= >" coding "," 5 "= >" ide ") $a3 = array (" 6 "= >" cpp "," 7 "= >" java ", 8 = >" engineer ") Output: Array ( [1] = > engineer)The following programs illustrate the array_uintersect() function:Program 1:PHP program to demonstrate the array_uintersect() function .
php
// PHP program for demonstration of work
// array_uintersect() function
// custom function
function
user_function (
$a
,
$b
)
{
if
(
$a
===
$b
)
{
return
0;
}
return
(
$a
>
$b
)? 1: -1;
}
// arrays
$a1
=
array
(
"a"
= >
"striver"
,
"b"
= >
"engineer"
,
"d"
= >
"raj"
);
$a2
=
array
(
"d"
= >
" articles "
,
" e "
= >
"raj"
,
"f"
= >
" coding "
);
$result
=
array_uintersect
(
$a1
,
$a2
,
"user_function"
);
print_r (
$result
);
?>
Output:Array ([d] = > raj)Program 2:PHP program to demonstrate how the array_uintersect() function works with three arrays.
php
// PHP program for demonstration work
// array_uintersect() function with 3 arrays
// custom function
function
user_function (
$a
,
$b
)
{
if
(
$a
===
$b
)
{
return
0;
}
return
(
$a
>
$b
)? 1: -1;
}
// 3 arrays
$a1
=
array
(
"1"
= >
"engineer"
,
"2"
= >
"for"
,
"3 "
= >
" geek "
,
"4"
= >
"coding"
);
$a2
=
array
(
"1"
= >
" engineer "
,
" 2 "
= >
"for"
,
"3"
= >
" php "
,
" 4 "
= >
" coding "
,
"5"
= >
"ide"
);
$a3
=
array
(
"6"
= >
" cpp "
,
" 7 "
= >
"java"
, 8 = >
"engineer"
);
$result
=
array_uintersect
(
$a1
,
$a2
,
$a3
,
"user_function"
);
print_r (
$result
);
?>
Output:Array ([1] = > engineer)Link :
http://php.net/manual/en/function.array-uintersect.php