|
|
PHP array_udiff_assoc() Function
|
Tutorials » Php »
|
Topic |
What is array_udiff_assoc() Function?
|
|
Explanation |
|
The "array_udiff_assoc()" function computes the difference of arrays with additional index check,
compares data by a callback function.
Syntax:
array_udiff_assoc(array1,array2,array3...,function)
In the above syntax "array1" and "array2" are compared automatically for keys, then in the
user defined function checks for the values, then returns an array of differing elements.
Example
<?php
function funct1($x1,$x2)
{
if ($x1===$x2)
{
return 0;
}
return 1;
}
$a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
$a2=array("a"=>"Cat","b"=>"Horse","c"=>"Dog");
print_r(array_udiff_assoc($a1,$a2,"funct1"));
?>
Result:
Array ( [b] Dog [c] => Horse )
In the above example the two arrays "a1", "a2" are compared for keys then for values to display the different elements.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|