Home >>PHP Array Functions >PHP array_uintersect_assoc() Function
PHP array_uintersect_assoc() function is used to calculate the intersection of the array of keys for different values of two or more given input arrays. The first array get compared to all others array by the user-defined function and returns the matches.
Syntax:
array_uintersect_assoc(array1, array2, array3, ..., function);
Parameter | Description |
---|---|
array1 | This is a requiredparameter.This parameter defines array to compare from. |
array2 | This is a requiredparameter.This parameter definesan array to compare against. |
array3,... | This is an optionalparameter.This parameter definesmore arrays to compare against. |
myfunction | This is a requiredparameter.This parameter definesa string that define a callable comparison function. |
Here is an example of array_uintersect_assoc() function in PHP:
<html> <body> <pre> <?php function compare($x,$y) { if ($x===$y) { return 0; } return ($x>$y)?1:-1; } $x=array("a"=>"1","b"=>"2","c"=>"3","d"=>"4","e"=>"5"); $y=array("a"=>"1","b"=>"2","c"=>"3"); $result=array_uintersect_assoc($x,$y,"compare"); print_r($result); ?> </pre> </body> </html>
Array ( [a] => 1 [b] => 2 [c] => 3 )
Example 2:
<html> <body> <pre> <?php function compare($x,$y) { if ($x===$y) { return 0; } return ($x>$y)?1:-1; } $x=array("a"=>"1","b"=>"2","c"=>"3","d"=>"4","e"=>"5"); $y=array("a"=>"1","b"=>"2","c"=>"3","d"=>"5","e"=>6); $result=array_uintersect_assoc($x,$y,"compare"); print_r($result); ?> </pre> </body> </html>
Array ( [a] => 1 [b] => 2 [c] => 3 )