PHP Array_udiff () and ARRAY_UDIFF_ASSOC () Use the example tutorial, let's take a look at Array_udiff () first.
Definitions and usage
The Array_udiff () function compares two or more arrays in the user's function, and returns an array containing the contents from the first array, if the user's function allows it. The user's function compares the array value and returns a numeric value, positive (1) If the returned array should contain this factor, 0 or minus (-1) if not.
Grammar
Array_udiff (array1,array2,array3...,function)
Parameter description array1 requirements. The first array of arrays, others will be required with array2. An array is optional relative to the first array array3. An array is relative to the first array functional requirements. User name features tips and hints: You can compare the first array to an array, or have you like it. Note: Only values are used for comparisons. such as <?php
function MyFunction ($v 1, $v 2)
{
if ($v 1=== $v 2)
{
return 0;
}
return 1;
}
$a 1=array ("a" => "Cat", "B" => "Dog", "C" => "horse");
$a 2=array (1=> "Cat",2=> "Dog",3=> "Fish");
Print_r (Array_udiff ($a 1, $a 2, "myfunction"));
?>
Output results.
Array ([C] => horse)
And look at Array_udiff_assoc ()
Definitions and usage
The ARRAY_UDIFF_ASSOC () function compares two or more arrays, either in the built-in features and in the user's function,
It then returns an array containing the contents from the first array if it is allowed to function. Built-in feature comparison keys. The user's function compares the value and returns a numeric value, positive (1) If the returned array should contain this factor, 0 or minus (-1) if not.
Grammar
ARRAY_UDIFF_ASSOC (array1,array2,array3...,function)
Parameter description
Array1 requirements. Array of the first array, others will be associated with the
Array2 requirements. An array is relative to the first array
Array3 Optional. An array is relative to the first array
Functional requirements. The function of the user name
Tips and Instructions
Tip: You can compare the first array to an array, or have you like it.
Note: For comparisons, the key is to use built-in features and values that are used in the user's capabilities.
For example
<?php
function MyFunction ($v 1, $v 2)
{
if ($v 1=== $v 2)
{
return 0;
}
return 1;
}
$a 1=array ("a" => "Cat", "B" => "Dog", "C" => "horse");
$a 2=array ("a" => "Cat", "B" => "Horse", "C" => "Dog");
Print_r (ARRAY_UDIFF_ASSOC ($a 1, $a 2, "myfunction"));
?>
Output results.
Array ([b] Dog [C] => horse)