Is there a difference between !== and != in PHP?

在PHP中!==!=有区别吗?


The != operator compares value, while the !== operator compares type as well.

That means this:

var_dump(5!="5"); // bool(false)
var_dump(5!=="5"); // bool(true), because "5" and 5 are of different types

!= is the inverse of the == operator, which checks equality across types

!== is the inverse of the === operator, which checks equality only for things of the same type.


!= is for "not equal", while !== is for "not identical". For example:

'1' != 1   # evaluates to false, because '1' equals 1
'1' !== 1  # evaluates to true, because '1' is of a different type than 1
链接地址: http://www.djcxy.com/p/1802.html

上一篇: 比较,!==与!=

下一篇: 在PHP中!==和!=有区别吗?