Latest web development tutorials

PHP array_intersect_ukey () function

PHP Array Reference Complete PHP Array Reference

Examples

Keys for comparison of two arrays (using a user-defined comparison function keys), and returns the intersection:

<?php
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}

$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"blue","b"=>"black","e"=>"blue");

$result=array_intersect_ukey($a1,$a2,"myfunction");
print_r($result);
?>

Running instance »

Definition and Usage

array_intersect_ukey () function is used to compare two (or more) key name of the array, and returns the intersection.

Note: This function uses a user-defined function that compares keys!

This function compares two (or more) key name of the array, and returns an intersection array includes all the compared array (array1), and also in any other parameter array (array2 or array3 etc. key name) in the.

array3, etc.


grammar

array_intersect_ukey( array1,array2,array3...,myfunction )

参数 描述
array1 必需。与其他数组进行比较的第一个数组。
array2 必需。与第一个数组进行比较的数组。
array3,... 可选。与第一个数组进行比较的其他数组。
myfunction 必需。一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。

technical details

return value: It returns an intersection array includes all the compared array (array1), and also in any other parameter array (array2 or array3 etc.) in the key name.
PHP version: 5.1.0+

More examples

Example 1

Three keys for comparison array (using a user-defined comparison function keys), and returns the intersection:

<?php
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}

$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"black","b"=>"yellow","d"=>"brown");
$a3=array("e"=>"purple","f"=>"white","a"=>"gold");

$result=array_intersect_ukey($a1,$a2,$a3,"myfunction");
print_r($result);
?>

Running instance »


PHP Array Reference Complete PHP Array Reference