Jump to content

Is a compound conditional possible?


RIRedinPA

Recommended Posts

if i recall correctly (which i probably dont) i think it is.

 

i remember doing this years ago and working out that the brackets increase the term(s) in the order of precedence but it may have been with perl and not php.

 

heres an idea: try it out and see if it does what you expect with given data.

 

PS: sorry they dont exactly change the order of precendence - they group the logical terms together so they have to be met as a single term. but like i said i think this may have worked in perl.

heres an idea: try it out and see if it does what you expect with given data.

 

Thanks for the reply. I did test it in objective-c and it worked fine there. I was holding off doing it in my php code because I simplified it a lot for the post, to do this in my actual code will require a big honking bit of writing in the //do something part and before the if and I just wanted a quick answer here before I ventured into the weeds. Plus this makes a searchable record for something like this which might help out some other poor lost soul down the road. That's me, a giver to my fellow man...

of course it is possible...

 

 

$a = true;
$x = false;
$b = true;


if ($a != $x || ($a == $x && $b))
{
  //code
}
else
{
   // other code
}

Is equivalent to:

if (true || (false && true))
  // code

which in this case evaluates to true.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.