Page 1 of 1

Correct use for "if (this and that) {}"

Posted: Fri Jun 21, 2002 11:18 pm
by gxpark
Hi,

I can't seem to get a simple "if" instruction to work:

if ($thisvar and !somefunc()) { ... }

When $thisvar is true, it always executes the conditional code, no matter the value returned by somefunc().

What am I doing wrong?

Thanks in advance.

Posted: Sat Jun 22, 2002 1:40 am
by e+
It doesn't really answer your question but have you tried setting the output of the function to some variable and then test that instead ie

Code: Select all

$anothervar = somefunction();
if ($thisvar and !$anothervar) { ... }
this way you can try and debug by echoing out $anothervar and seing what it looks like. (not that you can't just echo out the somefunction() anyway)

Posted: Sat Jun 22, 2002 5:02 pm
by gxpark
Thanks. I've found the problem, it's related to "switch", so I'll post another question :)

Posted: Sat Jun 22, 2002 5:37 pm
by Sevengraff
PHP will accept if ($b = 1 and $d = 3) ??? I thought you had to use &&

Posted: Sat Jun 22, 2002 5:54 pm
by will
nope.... using 'and' in place of '&&' works fine..... at least in this case, not sure about others, but i believe it will.