== checks loose equality, comparing values after type juggling, so PHP may convert one side first. === checks strict equality and is true only when the value and the type both match, with no conversion.
$a = "5"; // string
$b = 5; // integer
var_dump($a == $b); // true (values equal after conversion)
var_dump($a === $b); // false (different types)
Loose comparison causes surprises. Before PHP 8, 0 == "foo" was true, because PHP turned the string into the number 0. Since PHP 8, a number compared with a non-numeric string is compared as strings, so the result is false. Numeric strings still compare as numbers, so "1" == "01" is true.
Use === and !== by default, especially where 0, "" and null can appear. Reach for == only when the conversion is what you want.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓