PHP array_udiff_uassoc() Function
What is array_udiff_uassoc() Function?
Explanation
The "array_udiff_uassoc()" function compares the difference of arrays with additional index check, compares values and keys or indexes by two different user defined functions.
Syntax:
array_udiff_uassoc(array1,array2,array3...,function1,function2)
In the above syntax "array1" and "array2" are compared in the first user defined function for keys, then in the second user defined function for the value, then returns an array of differing element from "array1".
Example :
<?php
function funct1_key($x1,$x2)
{
if ($x1===$x2)
{
return 0;
}
return 1;
}
function funct2_value($x1,$x2)
{
if ($x1===$x2)
{
return 0;
}
return 1;
}
$a=array("a"=>"Orange","b"=>"Guava","c"=>"Apple");
$b=array("a"=>"Orange","b"=>"Guava","c"=>"Cherry");
print_r(array_udiff_uassoc($a,$b,"funct1_key","funct2_value"));
?>
Result :
Array ([c]=> Apple)
In the above example the keys are checked using "funct1_key", then the values using "funct2_value", then the difference values are returned in an array.