Operator is used to perform operation on variable and values. Comparison Operators are used to compare two values.
Given below the complete list of available comparison operator in PHP :
| OPERATOR | NAME | EXAMPLE |
| = = | is equal to | 5= =8 returns false |
| != | is not equal | 5!=8 returns true |
| <> | is not equal | 5<>8 returns true |
| > | is greater than | 5>8 returns false |
| < | is less than | 5<8 returns true |
| >= | is greater than or equal to | 5>=8 returns false |
| <= | is less than or equal to | 5<=8 returns true |
Given below example will give you a clear idea how to use comparison operator :
<?php $a=3; $b=21; $c=30; echo $a=$b ? "true\n" : "false\n"; echo "<br/>"; echo $b!=$c ? "true\n" : "false\n"; echo "<br/>"; echo $c>$a ? "true\n" : "false\n"; ?>
true
true
true