PHP array_uintersect_uassoc: Compute Array Intersection with Index Checks Using Callback Functions
array_uintersect_uassoc is a PHP function that returns the intersection of multiple arrays while comparing both values and keys using user-defined callback functions, and the article explains its syntax, parameters, usage, and provides a complete example with expected output.
array_uintersect_uassoc() computes the intersection of arrays while also checking the keys, using user‑supplied callback functions to compare both data and indexes.
Signature:
array array_uintersect_uassoc ( array $array1 , array $array2 , callable $data_compare_func , callable $key_compare_func )Parameters:
$array1 – The first array.
$array2 – The second array.
$data_compare_func – Callback that returns <0, 0, >0 when the first value is less than, equal to, or greater than the second.
$key_compare_func – Callback that compares the keys.
Return value: An array containing all values that exist in $array1 and also appear in the other arrays, with matching keys according to the callbacks.
Example:
<?php
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "d" => "red");
$array2 = array("a" => "GREEN", "b" => "brown", "c" => "yellow", "d" => "red");
print_r(array_uintersect_uassoc($array1, $array2, "strcasecmp", "strcasecmp"));
?>Output:
Array
(
[a] => green
[b] => brown
)Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
