开发者

What's the difference between !== and != in PHP? [duplicate]

开发者 https://www.devze.com 2022-12-11 23:32 出处:网络
This question already exists: Closed 13 years ago. Possible Duplicate: php ==开发者_运维问答 vs === operator
This question already exists: Closed 13 years ago.

Possible Duplicate:

php ==开发者_运维问答 vs === operator

What's the difference between !== and != in PHP?


!== is strict not equal and which does not do type conversion

!= is not equal which does type conversion before checking


=== AND !== checks if the values compared have the same type (eg: int, string, etc.) and have the same values

While...

== AND != only compares the values


"1" != 1     // False
"1" !== 1    // True

It's a type thing. !== takes into account the types of its operands, while != does not (the implicit conversion makes the first conditional false).


== is only true if the values are equal. === is only true if the values and types are equal.


the triple equal also make sure the two variable are from the same type

1 == `1` // is ok
1 === `1` // is not same.


Both are comparion operators

  • $a !== $b Return TRUE if $a is not equal to $b, or they are not of the same type.
  • $a != $b Return TRUE if $a is not equal to $b.
0

精彩评论

暂无评论...
验证码 换一张
取 消