jamieolney jamieolney - 25 days ago 13
PHP Question

PHP If URL contains only a certain parameter

I understand I can use the following to see if the parameter p exists in the URL. However this will also work if there is also a q, t, r etc parameter


if(isset($_GET['p'])) {}


I also know that the following sees if there is any parameter set


if(count($_GET)) {}


However what i need is:

If ONLY parameter p exists -> do something... else if parameter p exists and any other parameter exists else do something... else if parameter != p , or no parameter exists - do something else

Any tips would be much appreciated

Answer
if(isset($_GET['p']) && count($_GET['p']) == 1){
//do something
} else if (isset($_GET['p'])){
//do something
} else {
//do something else
}
Comments