Comparison OperatorsComparison operators, as their name implies, allow you to compare two values. You may also be interested in viewing the type comparison tables, as they show examples of various type related comparisons.
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.
<?php For various types, comparison is done according to the following table (in order).
Example #1 Transcription of standard array comparison
<?php See also strcasecmp, strcmp, Array operators, and the manual section on Types. Warning
Comparison of floating point numbersBecause of the way floats are represented internally, you should not test two floats for equality. See the documentation for float for more information. Ternary OperatorAnother conditional operator is the "?:" (or ternary) operator. Example #2 Assigning a default value
<?php TRUE , and
expr3 if
expr1 evaluates to FALSE .
Since PHP 5.3, it is possible to leave out the middle part of the ternary
operator. Expression expr1 ?: expr3 returns
expr1 if expr1
evaluates to
|