Home  >  Article  >  Backend Development  >  A brief analysis of the difference between three equal signs (===) and two equal signs (==) in PHP_PHP Tutorial

A brief analysis of the difference between three equal signs (===) and two equal signs (==) in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:59:191039browse

Let’s give an example first:
For example, a function of yours will return these situations:
1. Numbers greater than 0
2. Numbers less than 0
3. A number equal to 0 (that is, 0)
4. False (when failure)
At this time, if you want to capture the failure situation, you must use === instead of Use ==
because == will not only match the 4th case, but also the 3rd case, because 0 is also false!

Three equal signs mean that the types of comparison objects must also be consistent. Two equal signs indicate that the condition is satisfied as long as the values ​​are equal.

Let’s add some more:
$a='2';//Character type 2
$b=2;//Numeric type 2
$a==$b , is correct, both are 2
$a===$b, which is incorrect because $a is character type and $b is numeric type. Although the value is the same, the type is different.
There is also the "0" mentioned in "linvo1986 - Level 6".

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328150.htmlTechArticleFirst give an example: For example, a function of yours will return these situations: 1. Numbers greater than 0 2. Numbers less than 0 3. Numbers equal to 0 (that is, 0) 4. False (when failed) At this time, if you...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn