Jump to content

Just wondering


Andy-H

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/255445-just-wondering/
Share on other sites


   // 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?

Link to comment
https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309692
Share on other sites

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");

Link to comment
https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309695
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/255445-just-wondering/#findComment-1309830
Share on other sites

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.