Продолжим. Почему array_uintersect не compare values первого массива после sorting? По моему скромному мнению array_udiff
и array_uintersect
должны иметь схожие алгоритмы, но их нет. Зачем?Попытка понять поведение array_uintersect
$compare = function($a, $b) use(&$iteration_count)
{
echo("$a : $b\n");
$iteration_count++;
return strcmp($a, $b);
};
$a = array('a', 'b', 'c');
$b = array('x', 'y', 'z');
$iteration_count = 0;
echo "array_udiff:" . json_encode(array_udiff($a, $b, $compare)) . "\n";
echo "iterations: $iteration_count\n\n";
$iteration_count = 0;
echo "array_uintersect:" . json_encode(array_uintersect($a, $b, $compare)) . "\n";
echo "iterations: $iteration_count\n\n";
Выход
b : a
c : b
y : x
z : y
a : x
a : b
b : x
b : c
c : x
array_udiff:["a","b","c"]
iterations: 9
b : a
c : b
y : x
z : y
a : x // comparison started
b : x // but there is no comparison to skip values
c : x
array_uintersect:[]
iterations: 7