Page 1 of 1

If syntax

Posted: Tue Jun 25, 2002 4:41 am
by 9902468
Can I do or not like this:

Code: Select all

if ( (somethin == true && something_else == false) || (some != "yeah" && i_am_not == jeesus) ){

     // more code
 
}
Essentially I'm just putting one if and one elseif in the same if clause, Is this allowed, The idea should be pretty clear but let's say it once more:

Code: Select all

if ( (many conditions) || (alternative conditions, if first ones didn't add up) ) { 

}
Might be obvious to you but i'm a bit confused now, as i've tried it out and it works, it doesn't, it works... You get the idea...

Posted: Tue Jun 25, 2002 4:51 am
by twigletmac
That sort of syntax is fine and is especially useful for things like this:

Code: Select all

<?php
if ($this == 'something' && ($this2 == 'foo' || $this3 != 'bar')) &#123;
    // code
&#125;
?>
So that you don't have to nest if loops.

The code you put is fine but if it's not working as expected it might be an idea to echo all the relevant variables before running the loop, eg.

Code: Select all

<?php
echo '$somethin: '.$somethin;
echo '$something_else: '.$something_else;
echo '$some: '.$some;
echo '$i_am_not: '.$i_am_not;
if ( ($somethin == true && $something_else == false) || ($some != "yeah" && $i_am_not == jeesus) )&#123; 
     // more code 
&#125;
?>
Mac

Posted: Tue Jun 25, 2002 4:55 am
by 9902468
Thanks, now I'm free to hunt that bug down :)