Ben*_*Ben 11 php get isset is-empty
我想检查appURL中是否存在参数,但没有值.
例:
my_url.php?app
Run Code Online (Sandbox Code Playgroud)
我试过isset()和empty(),但不工作.我以前看过它,我忘记了.
Jay*_*itt 25
空是正确的.你想要使用两者一起设置和清空
if(isset($_GET['app']) && !empty($_GET['app'])){
echo "App = ".$_GET['app'];
} else {
echo "App is empty";
}
Run Code Online (Sandbox Code Playgroud)
empty应该工作(if(empty($_GET[var]))...),因为它检查以下内容:
以下内容被认为是空的:
"" (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)
以下是您的选择:
is_null - 查找变量是否为NULL
if(is_null($_GET[var])) ...
Run Code Online (Sandbox Code Playgroud)
defined - 检查给定的命名常量是否存在
if(defined($_GET[var])) ...
Run Code Online (Sandbox Code Playgroud)