PHP

PHP Menu

PHP

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

Definition

The array_diff_ukey() function compares the keys of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc, using a user-defined function to compare the keys.

Syntax

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

Parameters

Parameter Description
array1 Required. The array to compare from.
array2 Required. An array to compare against.
array3 Optional. More arrays to compare against.
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("cat" => 2, "lion" => 5, "zebra" => 8); $array2 = array("CAT" => 3, "FOX" => 1, "LION" => 5, "WOLF" => 7);
$result = array_diff_ukey($array1, $array2, "compare"); print_r($result);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods