Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_intersect_ukey() Function

PHP array_intersect_ukey() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Compare two arrays by theirkeys(using a user-defined function to compare keys), and return the intersection:

$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); ?>

Run Example »


Definition and Usage

The array_intersect_ukey() function compares two (or more) arrays by theirkeys , and returns the intersection.

**Note:** This function uses a user-defined function to compare keys!

This function compares the keys of two (or more) arrays and returns an intersection array containing all the keys in the compared array (array1) that are also present in any of the other argument arrays (array2 or array3 , etc.).

array3

, etc.


Syntax

array_intersect_ukey(

array1,array2,array3...,myfunction

)

Parameters Description
array1 Required. The first array to compare with the other arrays.
array2 Required. An array to compare with the first array.
array3,... Optional. Other arrays to compare with the first array.
myfunction Required. A string defining a callable comparison function. If the first argument is <, =, or > the second argument, the comparison function must return an integer <, =, or > 0 accordingly.

Technical Details

Return Value: Returns an intersection array containing all the keys and values in the compared array (array1) that are also present in any of the other argument arrays (array2 or array3 , etc.).
PHP Version: 5.1.0+

More examples

Example 1

Compare three arrays by theirkeys(using a user-defined function to compare keys), and return the intersection:

$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); ?>

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual