Jump to content

complicated if statement


Cardale

Recommended Posts

yes it is, but error catching with such a multi-conditional statement would be impossible since you could never know by that statement which variable/condition is failing.

 

so, yes this is possible, but no, i do not recommend it.

 

Do you mean by looking at that code alone or something else?

 

I figured it out btw.  It was a problem with my quotations.  I had set a value as "true" not true.  If you know what I mean.

oh , i thought that was just an example.

 

you're checking if $allowed is true twice in the same statement .. why?

 

yeah OR does break the statement up... what i would suggest is having brackets

I thought the || (or) broke the statement up.  Is that not the case?

 

yes the OR is breaking the statement up...

 

if($allowed==true && $options==false || $allowed==true && $options==true && $logged==true)

 

IF ($allowed == true AND $options == false OR $allowed == true AND $options == true AND $logged == true)

 

 

  • 3 months later...

just a quick tip...

with booleans like that. you don't necessarily have to compare them to true or false like that.  Now if you were doing a strict comparison, that'd be a different story in which you'd use three equals signs ===.

 

But you initial statement in your OP could pretty much be shortened to

if($allowed && !$options || ($allowed && $options && $logged))

note the use of the exclamation mark on the first $options.. that's the same as if $options == false.  I also used parentheses to combine the second part..

 

 

 

But more realistically, what's your problem? What's so complicated?

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.