array_uintersect_uassoc() function in php
0 2263
PHP array_uintersect_uassoc() function is used to return the intersection or match values of two or more arrays by comparing the values and keys with the help of two user-defined functions.
It is an inbuilt function of PHP.
Syntax:
array_uintersect_uassoc($array1,$array2,..,$arrayN,key_function,value_function);
here,
- $array1 is a PHP array which matched values is returned by this function.
- $array2 and $arrayN are php arrays which values and keys compared to $array1.
- key_function is a user define function which used to compare the keys of arrays. It is mandatory.
- value_function is also a user define function which used to compare the values of arrays. It is also mandatory.
Note:
The basic difference between array_uintersect_assoc() and array_uintersect_uassoc() is array_uintersect_uassoc() function contains two user defined comparison function one for keys and other for values.
Example:
<?php function keys_function($x,$y) { if ($x===$y) { return 0; } return ($x>$y)?1:-1; } function values_function($x,$y) { if ($x===$y) { return 0; } return ($x>$y)?1:-1; } $arr1=array("FRUIT1"=>"apple","FRUIT2"=>"guava","FRUIT3"=>"orange","FRUIT4"=>"fig"); $arr2=array("FRUIT1"=>"apple","FRUIT2"=>"fig","FRUIT3"=>"guava","FRUIT4"=>"guava"); $result=array_uintersect_uassoc($arr1,$arr2,"keys_function","values_function"); echo "<pre>"; print_r($result); ?>
Output:
Share:
Comments
Waiting for your comments