php-Arrays函数-array_intersect_ukey-用回调函数比较键名来计算数组的交集_PHP教程

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

array_intersect_ukey() 用回调函数比较键名来计算数组的交集

【功能】
         该函数将返回一个数组,
         该数组包含了所有在array1中但是不在其他任何参数数组中的键名的值。
         此比较是通过用户提供的回调函数进行的。
         如果认为第一个参数小于、等于、或大于第二个参数时,必须返回
         一个小于零、等于零,或大于零的整数
【使用范围】
         php5>5.1.0.
【使用】
         array array_intersect_ukey( array array1, array array2[,array...,callback key_compare_func]  )
         array1/必需/数组1
         array2/必需/比较的数组 最少得有一个
         array.../可选/用来比较的数组
         key_compare_func.../可选/为用户提供作为比较标准的回调函数
【示例】
[php]
function key_compare_func($key1,$key2) 

        if($key1==$key2) 
                return 0; 
        else if($key1>$key2) 
                return 1; 
        else 
                return -1; 
 

 
//分别定义两个数组 
$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)
}
*/ 

 


摘自 zuodefeng的笔记

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478210.htmlTechArticlearray_intersect_ukey() 用回调函数比较键名来计算数组的交集 【功能】 该函数将返回一个数组, 该数组包含了所有在array1中但是不在其他任何...
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 [email protected]
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!