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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.