How to use array udiff uassoc in PHP
In this article, I will explain how the array_udiff_uassoc() function can be used in PHP.
array_udiff_uassoc() function in PHP
-
The array_udiff_uassoc() function is used to compares two or more arrays, in two user-define functions.
-
The array_udiff_uassoc() function returns an array containing the elements from the first array.
-
In array_udiff_assoc() function, the key is used for comparison in the first function.
-
In array_udiff_assoc() function, the value is used for comparison in the second function.
Syntax
array_udiff_uassoc(array1,array2,array3....,function1,function2) |
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.
-
function1 function1 is required parameter. The function define by user that compares the array keys.
-
function2 function2 is required parameter. The function define by user that compares the array value.
Example
The following example show to how the array_udiff_uassoc() function can be used in PHP.
<html>
<body>
<h3 style="color: red;">array_udiff_uassoc() function example in PHP</h3>
<?php
function mydemo_key($s1,$s2)
{
if ($s1===$s2)
{
return 0;
}
return 1;
}
function mydemo_value($s1,$s2)
{
if ($s1===$s2)
{
return 0;
}
return 1;
}
$a1=array("a"=>"Nitin","b"=>"Priyanka","c"=>"Sachin");
$a2=array("a"=>"Ravi","b"=>"Nitin","c"=>"Priyanka");
echo("After array_udiff_uassoc function value is <br/>");
print_r(array_udiff_uassoc($a1,$a2,"mydemo_key","mydemo_value"));
?>
</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