if((isset($_GET[example]))&&($_GET['example']=='somevalue')){ ... }
Run Code Online (Sandbox Code Playgroud)
要么
if((!empty($_GET[example]))&&($_GET['example']=='somevalue')){ ... }
Run Code Online (Sandbox Code Playgroud)
要不就
if($_GET['example']=='somevalue'){ ... }
Run Code Online (Sandbox Code Playgroud)
我问为什么我看到很多例子,人们首先检查是否设置了$ _GET ['example']然后如果$ _GET ['example'] =='somevalue'(上面的第一个和第二个例子).我不明白为什么不使用最后的解决方案(如果$ _GET ['example'] =='somevalue'然后显然设置了$ _GET ['example']).
这个问题涉及任何其他变量($ _POST,$ _SERVER,ecc).
if((isset($_GET[example]))&&($_GET['example']=='somevalue')){ ... }
Run Code Online (Sandbox Code Playgroud)
是正确的,你想知道"变量"存在(或被设置)以便使用它.空只是检查它是否有任何数据.例如:
<?php
$foo= 0;
if (empty($foo)) { // True because $foo is empty
echo '$foo is either 0, empty, or not set at all';
}
if (isset($foo)) { // True because $foo is set
echo '$foo is set even though it is empty';
}
if (isset($var)) { // FALSE because $var was not declared before
...
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
525 次 |
| 最近记录: |