TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
< (less than) operator is a relational comparison operator that evaluates whether the value of the left operand is strictly smaller than the value of the right operand. It returns a boolean true if the condition is met, and false otherwise.
Evaluation Mechanics and Type Coercion
Because PHP is a dynamically typed language, the< operator performs implicit type coercion (type juggling) when comparing operands of different data types. The engine applies specific rules based on the types being compared:
- Numeric Comparison: When both operands are integers or floats, PHP performs a standard mathematical comparison.
- String Comparison: If both strings are valid numeric strings (e.g.,
"12"and"9"), PHP casts them to numbers and performs a mathematical comparison. If one or both strings are non-numeric, PHP performs a byte-by-byte lexicographical comparison based on the ASCII values of the characters. - Mixed Type (Number and String):
- PHP 8.0+: If the string is a valid numeric string (e.g.,
"123"), it is cast to a number and compared mathematically. If it is a non-numeric string (e.g.,"apple"), the number is cast to a string and compared lexicographically. - PHP 7.x and older: The string is implicitly cast to a number. Non-numeric strings evaluate to
0, and the comparison is performed mathematically.
- PHP 8.0+: If the string is a valid numeric string (e.g.,
- Boolean Comparison: When comparing a boolean with another data type, the other operand is implicitly cast to a boolean. The comparison is then performed strictly as a boolean comparison, where
falseis considered smaller thantrue. They are never cast to integers for this evaluation. - Array Comparison: Arrays are compared primarily by their size (count). An array with fewer elements is considered strictly less than an array with more elements. If the sizes are identical, PHP compares the elements sequentially only if both arrays have the exact same keys. If the arrays have the same number of elements but different keys, they are considered incomparable, and the
<operator evaluates tofalse.
Syntax and Behavior Visualization
Master PHP with Deep Grasping Methodology!Learn More





