PHP

PHP Menu

PHP

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

Definition

The array_diff_uassoc() function compares the keys and values of two (or more) arrays, and returns the differences, using a user-defined function to compare the keys.

Syntax

array_diff_uassoc(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.
array2 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($a, $b){ // Converting key to lowercase $a = strtolower($a); $b = strtolower($b);
if($a == $b){ return 0; } return ($a < $b) ? -1 : 1; }
// Sample arrays $array1 = array("a" => "apple", "b" => "ball", "c" => "cat", "dog"); $array2 = array("A" => "APPLE", "B" => "ball", "C" => "camel");
// Computing the difference $result = array_diff_uassoc($array1, $array2, "compare"); print_r($result);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods