Jump to content

If and elseif order of processing


mds1256
Go to solution Solved by Barand,

Recommended Posts

I am writing a script that will need to differentiate between if a combination of query strings exist.

 

So my question is does if/elseif follow the order of the if/elseif?

 

script.php?id=5

 

This would output one value

 

However if id and status exists then it should output something else.

 

script.php?id=5&status=active

 

See below, is the case that the first if will be evaluated if both status and id exist or could it also run the 2nd if statement as the id exists for both clauses?

 

Basically I only want the if with the get[‘id’] only to be executed only if there are no other query string parameters - or should I explicitly check to make sure there are no other query string parameters rather than just relying on the ordering of the if/elseif statement?

 


If(isset($_GET[‘id’]) && isset($_GET[‘status’]))
{
    echo “Both set”;
}
elseif(isset($_GET[‘id’]))
{
    echo “Just ID set”;
}

Link to comment
Share on other sites

  • Solution

See below, is the case that the first if will be evaluated if both status and id exist or could it also run the 2nd if statement as the id exists for both clauses?

 

What happens when you run it?

 

Whatever happens, that what it does - simple.

 

(It will stop look at other conditions as soon as it encounters a condition that evaluates as "true")

Edited by Barand
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.