I have created the following script for creating an array_uintersect alogrithm.
function compare2D($topic, $nomination): int
{
if (is_array($nomination)) {
return in_array($topic, $nomination) ? 0 : 1;
}
else if (is_array($topic)) {
return in_array($nomination, $topic) ? 0 : 1;
}
return strcmp($topic, $nomination);
}
$arr = [['REMOTE', 'REMOTE_PREMIUM'], 'SECURE'];
$topic = ['SECURE', 'REMOTE'];
var_dump(array_uintersect($topic, $arr, 'compare2D'));
When I run it, the result is
array(1) {
[0] =>
string(6) "SECURE"
}
Where it should be returning
array(2) {
[0] =>
string(6) "SECURE"
[1] =>
string(6) "REMOTE"
}
I found that this is only dependent on the array in 2nd argument to _uintersect having a sub-array at index 0 (first item).
When I move the sub-array to any position except for the 1st, i.e:
$arr = ['SECURE', ['REMOTE', 'REMOTE_PREMIUM']];
// or
$arr = ['SOMEVALUE', ['REMOTE', 'REMOTE_PREMIUM'], 'SECURE'];
...the intersection works fine, and I get the intended result above.
Does anyone know some algorithmic rules of php intersection that I am not aware of?
array(2) { [0] => string(4) "PLUM" [1] => string(9) "RASPBERRY" }return in_array($topic, $nomination) ? 0 : 1;, depends on what strings you put it it may or may not work. Unfortunately I haven't got time to investigate further. (see php.net/manual/en/function.array-uintersect.php#72841)