翻译自 stackoverflow

==比较的是变量的值是否相等,必要时可进行类型转换===比较的是变量是否具有相同的类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// "===" 意味着两个变量是相同的(值相等,类型相同)  
// "==" 意味着两个变量相等(经过类型转换后,值相等)
// "!=" 意味着两个变量不相等

false null array() 0 "0" 0x0 "0x0" "000" "0000"
false === == == == == == != != !=
null == === == == != == != != !=
array() == == === != != != != != !=
0 == == != === == === == == ==
"0" == != != == === == == == ==
0x0 == == != === == === == == ==
"0x0" != != != == == == === == ==
"000" != != != == == == == === ==
"0000" != != != == == == == == ===

注意:

  • "000" == "0000",这两个变量都可以转换成整数0,即经过类型转换后值相等
  • false == 0并且false == array()但是array()!=0