Jump to: navigation, search

Php array udiff assoc

From w3cyberlearnings

Contents

PHP function array_udiff_assoc

This function computes the difference of arrays with additional index check, compares data by a callback function

Syntax array_udiff_assoc

  • array1 : array input 1
  • array2 : array input 2
  • array3 : array input 3
  • callback : user-defined function
array_udiff_assoc(array1, array2, array3, callback);

Note

The two functions are almost the same. The array_udiff_assoc function compares the DATA with the user supplied function, and [[php array_diff_uassoc|array_diff_uassoc()]function compares the INDEX with the user supplied function.

Example 1

<?php

// call back function to compare two score
function check_score($vscore1, $vscore2) {
	if ($vscore1 == $vscore2) {
		return 0;
	} else if ($vscore1 > $vscore2) {
		return 1;
	} else {
		return -1;
	}
}

$check_score = array_udiff_assoc(
          array(4 => 'mark', 3 => 'john', 2 => 'jake'), 
          array(4 => 'mark', 3 => 'john', 12 => 'jake'), "check_score");

print_r($check_score);
?>


Output

Array ( [2] => jake )

Related Links


Navigation
Web
SQL
MISC
References