if(!$str)
$str 未定义 => 报Notice,TURE
$str = 0; => TURE
$str = "0"; => TURE
$str = ""; => TURE
$str = NULL; => TURE
$str = FALSE; => TURE
$str = array(); => TURE
if(empty($str))
$str 未定义 => TURE
$str = 0; => TURE
$str = "0"; => TURE
$str = ""; => TURE
$str = NULL; => TURE
$str = FALSE; => TURE
$str = array(); => TURE
结论:!$str 和 empty($str) 基本一样;empty($str)为非空或非零的值的时候返回FALSE。
if(!isset($str))
$str 未定义 => TURE
注意:empty() 和 isset() 只能用于变量,因为传递任何其它参数都将造成解析错误(如常量和对象的属性值)。若想检测常量是否已设置,可使用 defined()函数。
--------
if($str == "")
$str 未定义 => 报Notice,TURE
$str = 0; => TURE
$str = "0"; => FALSE
$str = ""; => TURE
$str = NULL; => TURE
$str = FALSE; => TURE
$str = array(); => FALSE
注意:
if ("0" == 0) => TRUE
PHP 中 isset 和 empty 的区别
最新推荐文章于 2024-09-20 11:12:55 发布