Definition and Usage
The array_uintersect_uassoc() function compares two or more arrays, in two user-made functions, and returns an array containing the elements from the first array, if the user-made functions allow it. The first user-made function compares array keys, and the second compares array values, and both returns a numeric value, 0 if the returned array should contain this element.Syntax
array_uintersect_uassoc(array1,array2,array3...,function1,function2)
| Parameter | Description |
|---|---|
| array1 | Required. The first array is the array that the others will be compared with |
| array2 | Required. An array to be compared with the first array |
| array3 | Optional. An array to be compared with the first array |
| function1 | Required. The name of the user-made function that compares the array keys |
| function2 | Required. The name of the user-made function that compares the array values |
Tips and Notes
Tip: You can compare the first array with one array, or as many as you like.Note: For comparison, the key is used in the first function and the value is used in the second. They are both user-made functions.
Example
<?php
function myfunc_key($v1,$v2)
{
if ($v1===$v2)
{
return 0;
}
return 1;
}
function myfunc_value($v1,$v2)
{
if ($v1===$v2)
{
return 0;
}
return 1;
}
$a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
$a2=array("a"=>"Cat","b"=>"Dog","c"=>"Dog");
print_r(array_uintersect_uassoc($a1,$a2,"myfunc_key","myfunc_value"));
?>
function myfunc_key($v1,$v2)
{
if ($v1===$v2)
{
return 0;
}
return 1;
}
function myfunc_value($v1,$v2)
{
if ($v1===$v2)
{
return 0;
}
return 1;
}
$a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
$a2=array("a"=>"Cat","b"=>"Dog","c"=>"Dog");
print_r(array_uintersect_uassoc($a1,$a2,"myfunc_key","myfunc_value"));
?>
Array ( [a] => Cat [b] => Dog )