mds1256 Posted February 11, 2018 Share Posted February 11, 2018 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”; } Quote Link to comment https://forums.phpfreaks.com/topic/306505-if-and-elseif-order-of-processing/ Share on other sites More sharing options...
Solution Barand Posted February 11, 2018 Solution Share Posted February 11, 2018 (edited) 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 February 11, 2018 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/306505-if-and-elseif-order-of-processing/#findComment-1556292 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.