What is the difference between three equal signs (===) and two equal signs (==) in php

WBOY
Release: 2016-07-25 08:57:02
Original
1634 people have browsed it
Do you know the difference between three equal signs (===) and two equal signs (==) in PHP? This article introduces it in detail for everyone. Friends in need can take a look.

To talk about the difference between three equal signs (===) and two equal signs (==) in PHP, let’s first look at an example: For example, 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) When quoting, to capture the failure situation, you must use ===, not == 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.

Added:

$a='2';//Character type 2 $b=2;//numeric type 2 $a==$b, is correct, both are 2 $a===$b 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".


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