On Jan 19, 2008 11:37 PM, Dave Smith <[EMAIL PROTECTED]> wrote:
> 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
>

One way to get this functionality is with the in_array() function.

if ( !in_array($var,Array('a','b','c','d','e')) ) doStuff();

Of course you'd have to have a few conditions in order for this to
save you any typing.

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to