How do I check if a $_GET parameter exists but has no value?

Ben picture Ben · Sep 19, 2012 · Viewed 48.9k times · Source

I want to check if the app parameter exists in the URL, but has no value.

Example:

my_url.php?app

I tried isset() and empty(), but don’t work. I’ve seen it done before and I forgot how.

Answer

Jay Hewitt picture Jay Hewitt · Sep 19, 2012

Empty is correct. You want to use both is set and empty together

if(isset($_GET['app']) && !empty($_GET['app'])){
    echo "App = ".$_GET['app'];
} else {
    echo "App is empty";
}