Jump to: navigation, search

Php array udiff

From w3cyberlearnings

Contents

PHP function array_udiff

This function computes the different of arrays values by using the user-defined function for data comparison.

Syntax array_udiff

  • array1: array input 1
  • array2: array input 2
  • array3: array input 3
  • callback: user-defined function for data comparison between arrays
array_udiff(array1, array2, ..., callback);

Example 1

  • check for the average score for two plays for each players.
<?php

$records = array('Alyssa' => 10, 'Emma' => 3, 'Landon' => 5);
$players = array('Alyssa' => 9.21, 'Emma' => 4, 'Landon' => 6);

function playercheck($v1, $v2) {
	$result = ($v1 + $v2) / 2;
	if ($result >= 9) {
		return 0;
	} else {
		return 1;
	}
}

$player_score = array_udiff($records, $players, 'playercheck');
print_r($player_score);
?>


Output


Array
(
    [Emma] => 3
    [Landon] => 5
)

Related Links


Navigation
Web
SQL
MISC
References