array_diff_uassoc() is a PHP function that performs an associative array difference operation. It compares the values of the input arrays and returns an array containing the values from the first array that are not present in any of the subsequent arrays.
Version Support: array_diff_uassoc() in PHP 8.5, array_diff_uassoc() in PHP 8.4, array_diff_uassoc() in PHP 8.3, array_diff_uassoc() in PHP 8.2, array_diff_uassoc() in PHP 8.1, array_diff_uassoc() in PHP 7.1, array_diff_uassoc() in PHP 7.2, array_diff_uassoc() in PHP 7.3, array_diff_uassoc() in PHP 7.4
The syntax of array_diff_uassoc() is as follows:
array_diff_uassoc(array $array, array $...$arrays, callable $key_compare_func)
Here:
→ $array is the array to be checked for differences.
→ $...$arrays are the arrays to be compared with.
→ $key_compare_func is a function that compares the keys of the arrays.
This function is similar to array_diff() but it uses a user-defined comparison function to determine whether the keys of the arrays are equal.
Here is an example:
$array1 = array("a" => 1, "b" => 2, "c" => 3);
$array2 = array("b" => 2, "c" => 3, "d" => 4);function key_compare_func($key1, $key2) {
return $key1 == $key2;
}$result = array_diff_uassoc($array1, $array2, key_compare_func );
print_r($result);
In this example, the result would be:
Array
(
[a] => 1
)
The key "a" is present in $array1 but not in $array2, so it is included in the result.