This statement will always be true
:
($var !== 1 || $var !== 2)
Because $var
can never simultaneously be both values, it will always not be at least one of the two values. Which satisfies the ||
operator.
If you want to know whether $var
is one of the two values:
($var === 1 || $var === 2)
If you want to know if $var
is neither of the two values, you can negate the condition:
(!($var === 1 || $var === 2))
Or individually negate the operators in the condition and use &&
instead of ||
(since all conditions need to be met to prove the negative, instead of just one condition to prove the positive):
($var !== 1 && $var !== 2)
Depending on readability and personal preference.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…