Home > Backend Development > PHP Tutorial > Analysis of the difference between three equal signs '===' and two equal signs '==' in PHP

Analysis of the difference between three equal signs '===' and two equal signs '==' in PHP

WBOY
Release: 2016-07-25 08:57:04
Original
1547 people have browsed it
Let’s analyze the difference between three equal signs === and two equal signs == in PHP. Friends in need can refer to it.

Recently, I want to study the specific difference between "===" and "==" in PHP. In fact, "===" is also used for comparison, but the comparison requirements are more stringent. It will require that the types on both sides are the same;

For example:

When $a=8; if($a==8.0) or if($a==8) both return TRUE; But if($a===8.0) returns false, because the two types are different, only if($a===8) returns true;

Suppose, a function will return the following situations: 1. Numbers greater than 0 2. Numbers less than 0 3. A number equal to 0 (that is, 0) 4. False (on failure) At this time, if you need to capture the failure situation, you must use === instead of ==. why? Because == will not only match the 4th situation, but also the 3rd situation, because 0 is also false.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template