Cardale Posted December 14, 2009 Share Posted December 14, 2009 I have a if statement I need some help on. if($allowed==true && $options==false || $allowed==true && $options==true && $logged==true) Is something like this possible with one if statement? Where can I read more about complicated if statements like this? Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/ Share on other sites More sharing options...
trq Posted December 14, 2009 Share Posted December 14, 2009 What is the problem with the statement you have? Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-977389 Share on other sites More sharing options...
mrMarcus Posted December 14, 2009 Share Posted December 14, 2009 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. Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-977390 Share on other sites More sharing options...
Cardale Posted December 14, 2009 Author Share Posted December 14, 2009 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. Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-977391 Share on other sites More sharing options...
mrMarcus Posted December 14, 2009 Share Posted December 14, 2009 oh , i thought that was just an example. you're checking if $allowed is true twice in the same statement .. why? Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-977394 Share on other sites More sharing options...
Cardale Posted December 14, 2009 Author Share Posted December 14, 2009 oh , i thought that was just an example. you're checking if $allowed is true twice in the same statement .. why? I thought the || (or) broke the statement up. Is that not the case? Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-977396 Share on other sites More sharing options...
seany123 Posted December 15, 2009 Share Posted December 15, 2009 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) Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-977413 Share on other sites More sharing options...
andrewgauger Posted March 19, 2010 Share Posted March 19, 2010 Personally I like: IF($allowed==true && ($options==false || $logged==true)) This way it is no longer a complicated IF statement. Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-1028378 Share on other sites More sharing options...
Zane Posted March 19, 2010 Share Posted March 19, 2010 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? Link to comment https://forums.phpfreaks.com/topic/185152-complicated-if-statement/#findComment-1028381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.