php-Arrays function-array_diff_ukey-use callback function to compare key names to calculate the difference set of array_PHP tutorial

WBOY
Release: 2016-07-13 17:51:20
Original
1057 people have browsed it

array_diff_ukey() function uses the callback function to compare the key names and calculate the difference set of the array

【Function】
This function will return an array,
This array contains the values ​​of all keys that are in array1 but are not in any other parameter array.
                                                                                  Note that the relationship remains unchanged. This comparison is performed through a user-supplied callback function.
If the first parameter is considered to be less than, equal to, or greater than the second parameter,
must be returned            An integer less than zero, equal to zero, or greater than zero
【Scope of use】
php5 > 5.1.0
【Use】
array array_diff_ukey( array array1, array array2[,array...,callback key_compare_func] )
           array1/required/array1
           array2/required/comparable array must have at least one
           array.../optional/array used for comparison
             key_compare_func.../Required/Provide users with a callback function as a comparison standard
【Example】
[php]
//Define callback function
function key_compare_func( $key1, $key2 )
{
If( $key1 == $key2 )
Return 0;
          else if( $key1 > $key2 )
Return 1;
            else  
Return -1;
}
//Define two arrays respectively
$array1 = array( "blue" => 1, "red" => 2, "green" => 3, "purple" => 4 );
$array2 = array( "green" => 5, "blue" => 6, "yellow" => 7, "cyan" => 8 );
print_r( array_diff_ukey( $array1, $array2, "key_compare_func" ) );
/*
Array
(
[red] => 2
[purple] => 4
)*/

Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478202.htmlTechArticlearray_diff_ukey() function uses the callback function to compare the key names to calculate the difference set of the array [Function] This function will return a Array, this array contains everything in array1 but not in any other...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!