Jump to: navigation, search

Php array uintersect uassoc

From w3cyberlearnings

Contents

PHP function array_uintersect_uassoc

This function compares two or more arrays with two user-defined functions. The first user-defined function will be used for the keys comparison, and the second function will be used for the values comparison. This comparison is based on the first array. When the function return 0, the array element will be return.

Syntax array_uintersect_uassoc

  • array1: array input.
  • array2: array input.
  • callback1: user-defined function for array keys comparison.
  • callback2: user-defined function for array values comparison.
array_uintersect_uassoc(array1, array2, array3,..,callback1, callback2);

Example 1

<?php

function func_key($v1, $v2) {
	if ($v1 === $v2) {
		return 0;
	}
	return 1;
}

function func_value($v1, $v2) {
	if ($v1 === $v2) {
		return 0;
	}
	return 1;
}

$group1 = array(
	 'Liam' => 'apple',
	 'Abana' => 'banana',
	 'Ababuo' => 'bee'
);
$group2 = array(
	 'Liam' => 'apple',
	 'Abana' => 'Banana',
	 'Ababuo' => 'bee'
);

$rs = array_uintersect_uassoc($group1, $group2, "func_key", "func_value");
print_r($rs);
?>

Output

Array
(
    [Liam] => apple
    [Ababuo] => bee
)

Related Links


Navigation
Web
SQL
MISC
References