How to learn PHP array_diff_uassoc () _php Tutorial

Source: Internet
Author: User

How to learn PHP Array_diff_uassoc ()


Definition and usage

The ARRAY_DIFF_UASSOC () function uses a user-defined callback function (callback) to perform an index check to calculate the difference between two or more arrays. Returns an array that contains the values in Array1 but not in any other parameter array.

Note that unlike the Array_diff () function, the key name is also compared.

The parameter function is a user-defined one that compares two arrays, and the function must have two parameters-that is, two key names to be compared. Therefore, the behavior of the function Array_diff_assoc () is reversed, and the latter is compared by an intrinsic function.

The key names in the returned array remain unchanged.

Grammar

ARRAY_DIFF_UASSOC (array1,array2,array3...,function)

Parameters

Describe

Array1 required. The first array to compare with the other array.

Array2 required. The array to compare with the first array.

Array3 is optional. The array to compare with the first array. Can have more than one.

function Required. The name of the user-defined function.

Example 1

$v 2) {return 1;} else {return-1;}} $a 1=array (0=> "Dog",1=> "Cat",2=> "Horse"); $a 2=array (3=> "Dog",1=> "Cat",5=> "Horse"); Print_r (ARRAY_DIFF_UASSOC ($a 1, $a 2, "MyFunction"))?>

Output:

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

Example 2

How to assign multiple arrays to the function:

$v 2) {return 1;} else {return-1;}} $a 1=array (0=> "Dog",1=> "Cat",2=> "Horse"); $a 2=array (3=> "Dog",1=> "Cat",5=> "Horse"); $a 3=array (6=> "Bird",0=> "Dog",5=> "Horse"); Print_r (ARRAY_DIFF_UASSOC ($a 1, $a 2, $a 3, "MyFunction"))?>

Output:

Array ([2] = Horse)

http://www.bkjia.com/PHPjc/834957.html www.bkjia.com true http://www.bkjia.com/PHPjc/834957.html techarticle How to learn php Array_diff_uassoc () Definition and usage the ARRAY_DIFF_UASSOC () function uses a user-defined callback function (callback) to do an index check to calculate the difference between two or more arrays. ...

  • 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.