Jump to content

If and elseif order of processing


mds1256

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

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

Link to comment
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.