php-arrays function-array_diff_ukey-using a callback function to compare the difference set of an array with a key name _php tutorial

Source: Internet
Author: User
The Array_diff_ukey () function uses a callback function to compare the difference set of an array to a key name

function
The function will return an array,
The array contains all the values in array1 but not the key names in any of the other parameter arrays.
Note that the association relationship remains the same. This comparison is done through a user-supplied callback function.
If you think that the first parameter is less than, equal to, or greater than the second argument, you must return a
An integer less than 0, equal to zero, or greater than 0
"Scope of Use"
PHP5 > 5.1.0
Use
Array Array_diff_ukey (array array1, array array2[,array...,callback Key_compare_func])
array1/Required/Array 1
array2/required/Compared arrays must have at least one
Array.../Optional/used to compare the array
Key_compare_func.../Required/provides the user with a callback function as a standard for comparison
Example
[PHP]
Defining callback Functions
function Key_compare_func ($key 1, $key 2)
{
if ($key 1 = = $key 2)
return 0;
else if ($key 1 > $key 2)
return 1;
Else
return-1;
}
Define two arrays separately
$array 1 = Array ("Blue" = 1, "Red" = 2, "green" = 3, "purple" = 4);
$array 2 = Array ("green" = 5, "Blue" = 6, "Yellow" = 7, "cyan" = 8);
Print_r (Array_diff_ukey ($array 1, $array 2, "Key_compare_func"));
/*
Array
(
[Red] = 2
[Purple] = 4
)*/

Excerpts from Zuodefeng's notes

http://www.bkjia.com/PHPjc/478202.html www.bkjia.com true http://www.bkjia.com/PHPjc/478202.html techarticle The Array_diff_ukey () function uses a callback function to compare the difference set of an array with a key name "function" The function returns an array that contains all the array1 but not any other ...

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