Compare string and array
- by alex
Hello all!
I have an array and variable.
If the variable does not exist in the array to be added, if there is - remove from the array.
Why not work?
$ar = ["a","b","c"];
$vr = "b";
foreach ($ar as $i => $value) {
if ($value == $vr) {
unset ($ar[$i]);
} else {
$ar[] = $vr;
$ar = array_unique($ar);
}
}
Thanks.