Andy-H Posted January 20, 2012 Share Posted January 20, 2012 Just wondering if I have an if statement like: if ( true || true || true ) { // do this } Is PHP clever enough to do this: if ( true || skip_me|| skip_me) { // do this } if ( false || true || skip_me ) { // do this } Like precedence for the leftmost conditions? Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/ Share on other sites More sharing options...
Andy-H Posted January 20, 2012 Author Share Posted January 20, 2012 I'm pretty sure it does, but it can't hurt to gather opinions. Bear that in mind before screaming "You're a dumb arse!" at me lol Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309684 Share on other sites More sharing options...
Andy-H Posted January 20, 2012 Author Share Posted January 20, 2012 In fact, would be better to know if MySQL does this? Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309686 Share on other sites More sharing options...
Andy-H Posted January 20, 2012 Author Share Posted January 20, 2012 Never mind, I can force precedence with parentheses. I'm a dumb arse lol Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309691 Share on other sites More sharing options...
Andy-H Posted January 20, 2012 Author Share Posted January 20, 2012 // prepare statements to check for/insert vehicle data $check_vehicle = $dbh->prepare("SELECT id FROM caravans WHERE owner = :owner AND ( ((( ( CRiS = :CRiS ) ) OR ( make = :make AND model = :model ) ) OR ( make = :make AND axel = :axel ) ) OR make = :make ) LIMIT 1"); So that should check for CRiS no. first, then make and model, then make and axel, then make, right? Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309692 Share on other sites More sharing options...
Andy-H Posted January 20, 2012 Author Share Posted January 20, 2012 Actually this is what I wanted to achieve: $check_vehicle = $dbh->prepare("SELECT id FROM caravans WHERE owner = :owner AND ( ((( ( LENGTH(:CRiS) AND CRiS = :CRiS ) ) OR ( LENGTH(:model) AND make = :make AND model = :model ) ) OR ( LENGTH(:axle) AND make = :make AND axle = :axle ) ) OR make = :make ) LIMIT 1"); Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309695 Share on other sites More sharing options...
Proletarian Posted January 21, 2012 Share Posted January 21, 2012 When in doubt, test your hypothesis. Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309704 Share on other sites More sharing options...
kicken Posted January 21, 2012 Share Posted January 21, 2012 Just wondering if I have an if statement like: ... Like precedence for the leftmost conditions? That is generally know as "short-circuit"ing and yes, php does do that. As soon as the condition is satisfied it will stop evaluating the remaining conditions. Quote Link to comment https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.