哪种方式是检查非空变量的正确方式


which way is correct way of checking not null variable

检查$value是否为空的更有效方法是什么

if ($value > 0 && $value !== 'null') { }

if (empty($value)) { }

PHP有一个优雅的is_null函数来检查变量是否真的是NULL

if (is_null($value)) {
    // so something
}

另一方面,empty检查空字符串('')、零(作为整数、浮点甚至字符串'0')、FALSE、空数组、未初始化变量和NULL s。

if(!empty($value)){
 //do stuff
}else{
// do somthing else
}