Array_diff_assoc () and array_diff_uassoc () function tutorial

Source: Internet
Author: User

Array_diff_assoc () and array_diff_uassoc () function tutorial

Definition and usage
The array_diff_assoc () function compares two or more arrays and returns the entry and value of an array from the first array, only when they do not exist in any other arrays.

Syntax

Array_diff_assoc (array1, array2, array3 ...)
Array1 requirements. The first array, the other will be required with array2. An array is optional relative to the first array array3. An array is relative to the first array. <? Php
$ A1 = array (0 => "Cat", 1 => "Dog";, 2 => "Horse ");
$ A2 = array (0 => "Rat", 1 => "Horse";, 2 => "Dog ");
$ A3 = array (0 => "Horse", 1 => "Dog", 2 => "Cat ");
Print_r (array_diff_assoc ($ a1, $ a2, $ a3 ));
?> Result. array ([0] => Cat [2] => Horse) Now let's take a look at the definition and usage of the array_diff_uassoc () function. The array_diff_uassoc () function compares two or more arrays, check whether there are differences, compare the previous key in a user-defined function, and then return the entry and value of an array from the first array if this function permits it. Array_diff_uassoc (array1, array2, array3., function) parameters describe the requirements of array1. The first array, the other will be required with array2. An array is optional relative to the first array array3. An array is a functional requirement relative to the first array. Note: You can compare the first array with an array, or you like it. Note: The two key values are used for automatic comparison. Then, in the User-Defined Function, only the key is being compared. Example 1 <? Php
Function myfunction ($ v1, $ v2)
{
If ($ v1 ===$ v2)
{
Return 0;
}
If ($ v1> $ v2)
{
Return 1;
}
Else
{
Return-1;
}
}
$ A1 = array (0 => "Dog", 1 => "Cat", 2 => "Horse ");
$ A2 = array (3 => "Dog", 1 => "Cat", 5 => "Horse ");
Print_r (array_diff_uassoc ($ a1, $ a2, "myfunction "));
?> Output is. Array ([0] => Dog [2] => Horse)

Related Article

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.