🐘 PHP Beginner

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

Answer

In PHP, == is the loose comparison operator — it compares values after type juggling (type coercion). For example, "1" == 1 returns true because PHP converts the string "1" to the integer 1. === is the strict comparison operator — it compares both value AND type without any coercion. So "1" === 1 returns false because one is a string and the other is an integer. Always prefer === for comparisons to avoid subtle bugs from unexpected type coercion. This is especially important when comparing with false, 0, null, and "", which are all loosely equal to each other in PHP.