RIRedinPA Posted March 18, 2010 Share Posted March 18, 2010 I made that term up but is doing something like this possible: if ($a != $x || ($a == $x && $b == true)) { //do something } Link to comment https://forums.phpfreaks.com/topic/195713-is-a-compound-conditional-possible/ Share on other sites More sharing options...
Catfish Posted March 18, 2010 Share Posted March 18, 2010 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. Link to comment https://forums.phpfreaks.com/topic/195713-is-a-compound-conditional-possible/#findComment-1028204 Share on other sites More sharing options...
RIRedinPA Posted March 18, 2010 Author Share Posted March 18, 2010 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... Link to comment https://forums.phpfreaks.com/topic/195713-is-a-compound-conditional-possible/#findComment-1028212 Share on other sites More sharing options...
Andy-H Posted March 18, 2010 Share Posted March 18, 2010 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. Link to comment https://forums.phpfreaks.com/topic/195713-is-a-compound-conditional-possible/#findComment-1028214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.