[UPHPU] testing multiple items in an if
Dave Smith
dave at thesmithfam.org
Sat Jan 19 23:37:31 MST 2008
Wade Preston Shearer wrote:
> if($var != 'a' || 'b')
It is valid syntax, but this condition will *always* be true, even if
$var neither equals 'a' nor 'b'. The reason: the expression 'b' is
considered true by PHP. You most definitely do not want to do this.
> if($var != 'a' && $var != 'b')
This is what you really wanted, and it's not the same as the first bit
of code. This condition is true if $var is neither 'a' nor 'b'.
I've often wished for syntax in C-style languages where you could do
what you wanted in the first bit of code, but it'll never happen (in
C-style languages anyway), because it'd be ambiguous to the
compiler/interpreter.
--Dave
More information about the UPHPU
mailing list