Hello.
What causes a string comparison to work using '==' but when using the '!=' or '!==', it doesn't work properly?
For example, I have in an variable versions of a word like 'allocate' in an array which is placed into a variable, '$status' in a 'foreach' loop. In an 'if' statement, I have the following:
DOESN'T WORK PROPERLY:
$status = $status_array[$i];
if (($status != "allocate1") || ($status != "allocate2") || ($status != "allocate3")) {
// do something
}
WORKS PROPERLY:
$status = $status_array[$i];
if (($status == "allocate1") || ($status == "allocate2") || ($status == "allocate3")) {
// do something
}
else {
// do something
}
Why would one method work and not the other? I'd rather use the 'short' version (without the 'else').
Thanks in advance.
EDIT: meant to add the '||' statements