I can't get this code to execute, I am sure that I wrote this incorrectly. Can someone assist please? Do you see something wrong?
if ($value1!=$value OR $value2 !=$value ) {
echo "something ";
exit();
}
else if ($value3!=$value OR $value4 !=$value) {
echo "something";
exit();
}
It's not clear what you're trying to do -- the comparisons between the variables and the variable names are not intuitive. That said, else
is unnecessary here.
You only need else
(or elseif
) if you don't want the code in the else
(or elseif
) block to execute when the if
statement is satisfied. Here, the if
block contains an exit()
. So, when the if
condition is satisfied, no more code will be executed, regardless of whether it's in if
or elseif
blocks.
Some more detail:
Here's how if
and else
work:
if (condition) {
// do this if condition is true
} elseif (condition_2) {
// do this if condition is false but condition_2 is true
} else {
// do this if neither condition nor condition_2 is true
}
/*
* code here will execute whether or not either condition or condition_2 is true
*/
In your code, you short-circuit everything after the if
block if the condition in your if
is true. That is, if $value1!=$value OR $value2 !=$value
, the script exits when you call exit();
.