is_null之间的区别“ == NULL”和“ === NULL”在PHP中 [英] difference between is_null "== NULL" and "=== NULL" in PHP

查看:177
本文介绍了is_null之间的区别“ == NULL”和“ === NULL”在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

php == vs ===运算符

我有以下代码片段对我来说,为什么用3种不同的方式评估NULL并不有意义。将变量 $ uploaded_filenames_array 视为UNKNOWN-我们不知道它仍然是数组还是NULL。这就是我们要检查的内容。

i have the following code fragment and it doesn't make sense to me why would NULL be evaluated in 3 different ways. Consider the variable $uploaded_filenames_array as UNKNOWN - we don't know whether it's still an array or a NULL. That's what we are trying to check.

//-----------------------------------------------
if (is_null($uploaded_filenames_array)){
    echo "is_null";
}
else{
    echo "is_NOT_null";
}
//-----------------------------------------------
if ($uploaded_filenames_array == NULL){
    echo "NULL stuff";
}
else{
    echo "not NULL stuff";
}
//-----------------------------------------------
if ($uploaded_filenames_array === NULL){
    echo "NULL identity";
}
else{
    echo "not NULL identity";
}
//-----------------------------------------------

我收到以下响应:

is_NOT_null 
NULL stuff 
not NULL identity 

有人可以帮助理解这三种检查NULL的程序设计区别是什么吗?

can somebody help to understand what is the programmatic difference between these 3 ways of checking NULL?

推荐答案

is_null($ a) $ a === null 相同。

$ a === null is_null($ a)保存一个函数调用,但这没关系,只需选择所需的样式即可。)

($a === null is bit faster than is_null($a) for saving one function call, but it doesn't matter, just choose the style you like.)

对于 == = == ,请阅读 PHP类型比较表

$ a === null 仅在 $ a null

但对于 == ,下面还返回 true

null == false
null == 0
null == array()
null == ""

这篇关于is_null之间的区别“ == NULL”和“ === NULL”在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆