Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The == (loose equality) operator in PHP evaluates whether two operands have equivalent values after performing implicit type coercion (type juggling). It returns a boolean true if the values are equivalent, and false otherwise.
$operand1 == $operand2
Because PHP is a dynamically typed language, the == operator attempts to resolve data type mismatches before comparing the underlying values. This behavior fundamentally distinguishes it from the strict equality operator (===), which requires both the value and the data type to be identical without any coercion. When evaluating operands of different types, the == operator applies the following internal casting rules (as of PHP 8.0):
  • Booleans: If either operand is a boolean, the other operand is cast to a boolean before comparison. Consequently, false is loosely equal to 0, 0.0, "" (empty string), null, and [] (empty array).
  • Numbers and Strings: If the string is a numeric string, it is converted to a number and compared mathematically. If the string is non-numeric, the number is converted to a string and a lexical string comparison is performed. For example, 0 == "string" and 0 == "" evaluate to false because the integer 0 is cast to the string "0".
  • Nulls: When compared to a string, null is implicitly cast to an empty string "" (making null == "" evaluate to true).
Master PHP with Deep Grasping Methodology!Learn More