array_uintersect_unassoc() function compares array keys and array values in user-defined functions and returns an array
array_uintersect_uassoc(arr1, arr2, arr3, … , compare_func1, compare_func2)
arr1 - The first array to be compared.
arr2 - The second array to be compared.
arr3 - More arrays to compare.
compare_func1 - Comparison function used to compare array keys. If the first argument is considered less than, equal to, or greater than the second argument, an integer less than, equal to, or greater than zero must be returned.
compare_func2 - Comparison function used to compare array values. If the first argument is considered less than, equal to, or greater than the second argument, an integer less than, equal to, or greater than zero must be returned.
array_uintersect_uassoc() function returns an array containing all values in the first array that do not appear in other parameters.
The following is an example-
Live Demo
<?php function compare_func_key($a, $b) { if ($a === $b) { return 0; } return ($a > $b)? 1:-1; } function compare_func_val($a, $b) { if ($a === $b) { return 0; } return ($a > $b)? 1:-1; } $arr1 = array("a" => "laptop", "b" => "keyboard", "c" => "mouse"); $arr2 = array("a" => "laptop", "b" => "keyboard", "c" => "headphone"); $res = array_uintersect_uassoc($arr1, $arr2, "compare_func_key", "compare_func_val"); print_r($res); ?>
The following is the output-
ArrayArray ( [a] => laptop [b] => keyboard )
The above is the detailed content of array_uintersect_uassoc() function in PHP. For more information, please follow other related articles on the PHP Chinese website!