I'm looping for string overlaps between two arrays, deleting those values where there is one, so that only the empty values of $check remain, in this case $check[5].
The second one, $check, is multidimensional.
$names = ["bob", "selena", "hailey", "rob", "justin", "robocop"];
$check = [
["justin"], //bob
["justin", "selena", "robocop"], //selena
["justin"], //hailey
["justin", "rob"], //rob
[], //justin
["justin", "selena", "bob"] //robocop
];
for ($i = 0; $i < count($names); $i++) {
for ($j = 0; $j < count($check); $j++) {
if (in_array($names[$i], $check[$j])) {
unset($check[$j]);
}
}
}
The first loop runs through $names, the second through $check.
If the current string from $names ($names[i])
is present in the current array of $check ($check[j])
the array is removed.
However, the console prints a warning: in_array() expects parameter 2 to be array, null given. I find this strange, because $check[j] should be equal to one of the arrays inside of $check.
Is there any way I can fix this?