Test script
$i = 0;
array_uintersect(['foo', 'bar'], ['baz', 'qux'], function($a, $b) use (&$i) {
print_r([$a, $b, $i++]);
});
Actual Result
Array
(
[0] => bar
[1] => foo
[2] => 0
)
Array
(
[0] => qux
[1] => baz
[2] => 1
)
Array
(
[0] => bar
[1] => qux
[2] => 2
)
Array
(
[0] => bar
[1] => foo
[2] => 3
)
Expected Result
Array
(
[0] => foo
[1] => baz
[2] => 0
)
Array
(
[0] => bar
[1] => qux
[2] => 1
)
In other words, what I am expecting to be passed to the callback is the current element of the left array, and the current element of the right array.
Furthermore, I would expect the same logic to apply if I were to pass an additional array to array_uintersect - one more argument being passed to the callback ($c, for example).
Can someone explain this behaviour?
$ihere. From the docs: "The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second."array_uintersecttries to intersect the values not the key php.net/manual/en/function.array-intersect-key.php