PHP Array_udiff () and ARRAY_UDIFF_ASSOC () using the example tutorial

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.