Php on the "==" pit

Today, the project team has a bug covert, different parameters of the test results, and later found to break the "==" stir up the issue.
For php novice, many times "==" inexplicable failure, resulting in an error of judgment, summarized here to do a "==" and "===" is.
1, "==" is an operator, comparing the value of two variables, data types do not compare.

2, "===" compare value and two types of variables. Judged more strictly.

example01:

$a = '123';
$b = 123;
var_dump($a === $b); //false;
var_dump($a == $b); //true

example02:

var_dump(0 == 1); // false
var_dump(0 == (bool)'all'); // false
var_dump(0 == 'all'); // TRUE, take care
var_dump(0 === 'all'); // false

Guess you like

Origin blog.51cto.com/13238147/2474097