PHP array_diff_uassoc function

Last Updated: February 11, 2022

array_diff_uassoc : compute the difference of arrays with additional index check. You can use the callback function fox index checking.

Syntax

array_diff_uassoc(array $array, array ...$arrays, callable $key_compare_func): array

Supports (PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
arrays Required. array to compare
arrays Required. arrays to be compare against
key_compare_func

Required. Callable function

callback(mixed $a, mixed $b): int

Return Values

The key comparison is done using the callback function and returns the results as an array

Example

<?php
function myfunction($a,$b)
{
if ($a===$b)
  {
  return 0;
  }
  return ($a>$b)?1:-1;
}

$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("d"=>"red","b"=>"green","e"=>"blue");

$result=array_diff_uassoc($a1,$a2,"myfunction");
print_r($result);

?>

Output

Array ( 
[a] => red 
[c] => blue 
)
Test