PHP

PHP Menu

PHP

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

Definition

The array_uintersect_uassoc() function compares the keys and values of two or more arrays and returns the matches using the user-defined key and value comparison functions.

Syntax

array_uintersect_uassoc(array1, array2, array3..., value_compare_function, key_compare_function)

Parameters

Parameter Description
array1 Required. The array to compare from.
array2 Required. An array to compare against.
array3... Optional. More arrays to compare against.
value_compare_function Required. The name of the user-defined function that compares the array values. 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.
key_compare_function Required. The name of the user-defined function that compares the array keys. 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 compareKey($x, $y) { if($x == $y){ return 0; } return ($x < $y) ? -1 : 1; } function compareValue($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", "dog"); $array2 = array("a" => "APPLE", "B" => "ball", "c" => "Cat");
$result = array_uintersect_uassoc($array1, $array2, "compareValue", "compareKey"); print_r($result);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods