How to Learn PHP array_diff_ukey ()

Source: Internet
Author: User

How to Learn PHP array_diff_ukey ()

Definition and usage

Array_diff_ukey () returns an array containing all the key names that appear in the array of array1 but are not displayed in any other parameter. Note that the link remains unchanged. Unlike array_diff (), the comparison is based on the key name rather than the value.

This comparison is performed through the callback function provided by the user. If the first parameter is considered to be less than, equal to, or greater than the second parameter, an integer less than zero, equal to zero, or greater than zero must be returned.

Syntax

Array_diff_ukey (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 => "Rat", 1 => "Bird", 5 => "Monkey"); print_r (array_diff_ukey ($ 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 => "Rat", 1 => "Bird", 5 => "Monkey"); $ a3 = array (6 => "Dog ", 7 => "Donkey", 0 => "Horse"); print_r (array_diff_ukey ($ 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.