You can take advantage of the fact that it array_search
returns only one corresponding element from the target array and use it to remove from $array2
:
$array1 = array(1.99);
$array2 = array(1.99, 1.99, 2.99);
foreach ($array1 as $remove) {
unset($array2[array_search($remove, $array2)]);
}
If it $array1
may contain elements that are not present in $array2
, then you need to add a check that the result is array_search
not false.
iainn source
share