为什么要检查isset()和!empty()
 isset和!empty是否有区别!empty 如果我这样做双布尔检查,这是正确的还是多余的? 有没有更简单的方法来做同样的事情? 
 isset($vars[1]) AND !empty($vars[1]) 
	
 这完全是多余的。  empty或多或less是!isset($foo) || !$foo简写  !isset($foo) || !$foo ,and !empty类似于isset($foo) && $foo 。 如果empty是做了相反的东西,再加上一个值的真实性检查。 
 或者换句话说, empty和!$foo是一样的,但是如果variables不存在则不会抛出警告。 这是这个函数的主要点:做一个布尔比较,而不用担心被设置的variables。 
手册就是这样写的:
empty()是(boolean) var的反义词, 除了没有设置variables时不会产生警告。
 您可以在这里简单地使用!empty($vars[1]) 。 
  isset()testing是否设置了variables,而不是null: 
http://us.php.net/manual/en/function.isset.php
 当variables设置为特定值时, empty()可以返回true: 
http://us.php.net/manual/en/function.empty.php
为了演示这一点,试试下面的代码$ the_var unassigned,设置为0,并设置为1。
 <?php #$the_var = 0; if (isset($the_var)) { echo "set"; } else { echo "not set"; } echo "\n"; if (empty($the_var)) { echo "empty"; } else { echo "not empty"; } ?> 
 $a = 0; if (isset($a)) { //$a is set because it has some value ,eg:0 echo '$a has value'; } if (!empty($a)) { //$a is empty because it has value 0 echo '$a is not empty'; } else { echo '$a is empty'; } 
接受的答案是不正确的。
isset() 不等于!empty()。
如果沿着这条路线走,你会创造出一些相当不愉快和难以debugging的错误。 例如尝试运行这个代码:
 <?php $s = ''; print "isset: '" . isset($s) . "'. "; print "!empty: '" . !empty($s) . "'"; ?> 
空只检查被引用的variables/数组有一个值,如果你检查PHP文档(空),你会看到这个东西被认为是静默
* "" (an empty string) * 0 (0 as an integer) * "0" (0 as a string) * NULL * FALSE * array() (an empty array) * var $var; (a variable declared, but without a value in a class)
而isset检查variablesisset,而不是null,这也可以在PHP文档(isset)中find
如果我们使用相同的页面通过提交button添加/编辑如下
 <input type="hidden" value="<?echo $_GET['edit_id'];?>" name="edit_id"> 
那么我们不应该使用
 isset($_POST['edit_id']) 
  bcoz edit_id是一直设置的,无论是添加还是编辑页面,我们都应该使用下面的检查条件 
 !empty($_POST['edit_id']) 
“空”:只适用于variables。 空对于不同的variablestypes可能意味着不同的事情(检查手册: http : //php.net/manual/en/function.empty.php )。
“isset”:检查variables是否存在,并检查一个真正的NULL值或假值。 可以通过调用“unset”来取消设置。 再次检查手册。
使用任何一个取决于您正在使用的variablestypes。
我会说,检查两者是比较安全的,因为首先检查variables是否存在,如果不是真的是NULL或空的。
没有必要。
如果variables不存在,则不会生成警告。 这意味着empty()实质上就是!isset($ var) || 的简洁等价物 $ var == false。
php.net