What is the difference between == and === in PHP?

Last updated 15 June 2026

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" and 1 == true are both true.

  • === (strict): No conversion: 0 === "0" is false because int and string differ.

  • 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
All PHP interview questions