What is the difference between == and === in PHP?
Last updated
Both compare equality, but == compares values after type coercion, while === requires both the value and the type to match with no conversion.
== (loose): Juggles types before comparing, so
0 == "0"and1 == trueare bothtrue.=== (strict): No conversion:
0 === "0"isfalsebecauseintandstringdiffer.Rule of thumb: prefer
===by default to avoid surprises from coercion.
- https://www.php.net/manual/en/language.operators.comparison.php
- https://www.php.net/manual/en/types.comparisons.php
- https://www.freecodecamp.org/news/how-php-type-juggling-works-explained-with-code-examples/
- https://dev.to/gitter4coding/8-key-questions-that-every-php-expert-should-answer-24jo
- https://www.geeksforgeeks.org/php/what-is-the-difference-between-and-in-php/
- https://www.webtrafficexchange.com/blog/double-and-triple-equal-operators-php
- https://www.php.net/manual/en/function.strpos.php