Jump to: navigation, search

Php array uintersect

From w3cyberlearnings

Contents

PHP function array_uintersect

This function compares two or more array. It returns an array key and value pairs from the first array that each of its elements existed in other arrays by doing the comparison in the user-defined function.

Syntax array_uintersect

  • array1: array input
  • array2: array input
  • array3: array input
  • callback: user-defined function
array_uintersect(array1, array2, array3..,callback);

Example 1

<?php

$score1 = array(40, 53, 43, 23);
$score2 = array(53, 40, 42, 43);
$score3 = array(34, 53, 43, 32);

function callback($v1, $v2) {
	if ($v1 === $v2) {
		return 0;
	} else if ($v1 > $v2) {
		return 1;
	} else {
		return -1;
	}
}

$score_intersect = array_uintersect($score1, $score2, $score3, "callback");

print_r($score_intersect);
?>

Output

Array
(
    [1] => 53
    [2] => 43
)

Related Links


Navigation
Web
SQL
MISC
References