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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

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

Post 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.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post 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)
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

Post by gxpark »

Thanks. I've found the problem, it's related to "switch", so I'll post another question :)
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

PHP will accept if ($b = 1 and $d = 3) ??? I thought you had to use &&
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

nope.... using 'and' in place of '&&' works fine..... at least in this case, not sure about others, but i believe it will.
Post Reply