PHP

PHP Menu

PHP

array_intersect_ukey() Function - Definition, Syntax, Parameters, Examples

Definition

The array_intersect_ukey() function compares the keys of two or more arrays and returns the matches or intersection using a user-defined key comparison function.

Syntax

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

Parameters

Parameter Description
array1 Required. The first array is the array that the others will be compared with.
array2 Required. An array to be compared with the first array.
array3 Optional. An array to be compared with the first array.
myfunction Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

Example

<?php
function compare($x, $y){ $x = strtolower($x); $y = strtolower($y); if($x == $y){ return 0; } return ($x < $y) ? -1 : 1; }
$array1 = array("a" => "apple", "b" => "ball", "c" => "cat"); $array2 = array("A" => "airplane", "x" => "xylophone", "y" => "yacht");
$result = array_intersect_ukey($array1, $array2, "compare"); print_r($result); echo "<br>";
$array3 = array("a" => "alligator", "b" => "balloon"); $result = array_intersect_ukey($array1, $array2, $array3, "strcasecmp"); print_r($result); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods