PHP

PHP Menu

PHP

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

Definition

The array_udiff_assoc() function compares the values of two or more arrays and returns the differences with additional key check using a user-defined value comparison function.

Syntax

array_udiff_assoc(array1, array2, array3, ..., 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.
function 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", "d" => "dog"); $array2 = array("A" => "APPLE", "b" => "ball", "c" => "camel", "d" => "DOG");
$result = array_udiff_assoc($array1, $array2, "compare"); print_r($result);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods