Explain the difference between == and === operators.

Beginner

Answer

  • == (Equal): Checks if values are equal after type juggling (type coercion)
  • === (Identical): Checks if values are equal AND of the same type (strict comparison)
$a = "5";  // string
$b = 5;    // integer
var_dump($a == $b);  // true (values equal after conversion)
var_dump($a === $b); // false (different types)