php-Arrays function-array_intersect_ukey-use callback function to compare key names to calculate the intersection of arrays_PHP tutorial

WBOY
Release: 2016-07-13 17:51:05
Original
1060 people have browsed it

array_intersect_ukey() uses callback function to compare key names to calculate the intersection of arrays

【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.
           This comparison is performed via 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_intersect_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.../optional/provides users with a callback function as a comparison standard
【Example】
[php]
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);
var_dump(array_intersect_ukey( $array1,$array2,'key_compare_func'));
/*
array(2) {
["blue"]=>
int(1)
["green"]=>
int(3)
}
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478210.htmlTechArticlearray_intersect_ukey() Use callback function to compare key names to calculate the intersection of arrays [Function] This function will return an 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