How to Learn PHP array_diff_uassoc ()

Source: Internet
Author: User

How to Learn PHP array_diff_uassoc ()

Definition and usage

The array_diff_uassoc () function uses the custom callback function (callback) for index check to calculate the difference set of two or more arrays. Returns an array that contains values in array1 but not in any other parameter array.

Note that, unlike the array_diff () function, the key name must be compared.

The Parameter function is a user-defined function used to compare two arrays. This function must contain two parameters-that is, two key names to be compared. Therefore, the behavior of the array_diff_assoc () function is the opposite. The latter is compared with the internal function.

The key names of the returned array remain unchanged.

Syntax

Array_diff_uassoc (array1, array2, array3., function)

 

Parameters

Description

 

Array1 is required. The first array to be compared with other arrays.

Array2 is required. The array to be compared with the first array.

Array3 is optional. The array to be compared with the first array. There can be multiple.

Required. The name of the User-Defined Function.

 

 

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:

Array ([0] => Dog [2] => Horse)

 

 

Example 2

How to assign multiple arrays to the function:

<? 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"); $ a3 = array (6 => "Bird ", 0 => "Dog", 5 => "Horse"); print_r (array_diff_uassoc ($ a1, $ a2, $ a3, "myfunction");?>

Output:

Array ([2] => 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.