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.
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";
}
empty
should be working (if(empty($_GET[var]))...
) as it checks the following:
The following things are considered to be empty:
"" (an empty string) 0 (0 as an integer) 0.0 (0 as a float) "0" (0 as a string) NULL FALSE array() (an empty array) $var; (a variable declared, but without a value)
Here are your alternatives:
is_null
- Finds whether a variable is NULL
if(is_null($_GET[var])) ...
defined
- Checks whether a given named constant exists
if(defined($_GET[var])) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With