array_uintersect() function in PHP


The array_uintersect() function compares array values in a user-made function and returns an array. It returns an array containing all the values of the first array that are not present in any of the other parameters.

Syntax

array_uintersect(arr1, arr2, arr3, … , compare_func)

Parameters

  • arr1 − The first array to compare from.

  • arr2 − The second array to be compared with.

  • arr3 − More arrays to compare.

  • compare_func − The comparison function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Return

The array_uintersect() function returns an array containing all the values of the first array that are not present in any of the other parameters.

Example

The following is an example −

 Live Demo

<?php
function compare_func($a, $b) {
   if ($a === $b) {
      return 0;
   }
   return ($a > $b)? 1:-1;
}
$arr1 = array("p"=>"one","q"=>"two","r"=>"three");
$arr2 = array("p"=>"three","q"=>"four","s"=>"three");
$res = array_uintersect($arr1, $arr2, "compare_func");
print_r($res);
?>

Output

The following is the output −

Array
(
[r] => three
)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

39 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements