How to use array udiff in PHP
In this article, I will explain about how the array_udiff() function can be used in PHP.
array_udiff() function in PHP
-
The array_udiff() function is used to compare two or more arrays, in a user-define function.
-
In array_diff_uassoc() function, only the value is used in the comparison.
-
The array_udiff() function returns an array containing the elements from the first array.
Syntax
array_udiff(array1,array2,array3....,function) |
Parameter
-
array1 array1 is required parameter. The first array is the array which will be compared with other arrays.
-
array2 array2 is required parameter. An array to be compared with the first array.
-
array3 array3 is optional parameter. An array to be compared with the first array.
-
function function is required parameter. The function made by user.
Example
The following example show to how the array_udiff() function can be used in PHP.
<html>
<body>
<h3 style="color: darkolivegreen;">array_udiff() function example in PHP</h3>
<?php
function myfunction($v1,$v2)
{
if ($v1===$v2)
{
return 0;
}
return 1;
}
$a1=array("a"=>"Student","b"=>"Teacher","c"=>"Engg.");
$a2=array(1=>"Doctor",2=>"Teacher",3=>"Worker");
echo("After comparison value is <br/>");
print_r(array_udiff($a1,$a2,"myfunction"));
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here