|
|
PHP array_udiff() Function
|
Tutorials » Php »
|
Topic |
What is array_udiff() Function?
|
|
Explanation |
|
The "array_udiff()" function computes the difference of arrays by using a callback function for data comparison.
Syntax:
array_udiff(array1,array2,array3...,function)
In the above syntax "array2" is compared with "array1" in a user defined function,to return the elements of "array1" in
an array.
Example
<?php
function funct1($x1,$x2)
{
if ($x1===$x2)
{
return 0;
}
return 1;
}
$a1=array("a"=>"Orange","b"=>"Guava","c"=>"Apple");
$b2=array("1"=>"Orange","2"=>"Guava","3"=>"Cherry");
print_r(array_udiff($a1,$b2,"funct1"));
?>
Result:
Array ([c]=> Apple)
In the above example the arrays are compared for difference using "funct1", then the difference values are returned in an array.
|
|
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.
|
|
|
|