Home >>PHP Tutorial >PHP Comparative Operators
Operatos | Description |
---|---|
== | Equal to |
=== | Equal to and of the same type |
!= | Not equal to |
!== | Not equal to and of the same type |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
<?php $x=10; $y=10.0; echo ($x==$y); //it returns true because both the variable contains same value. echo ($x===$y); /*it returns false because === strongly compares. here both variable contain same value i.e 10 but different datatype one is integer and another is float.*/ ?>
<?php //another example $bool=(boolean)1; $int=(integer)1; //return true because both have same value. echo ($bool==$int); //return false because both have same value but diff data type echo ($bool===$int); ?>
<?php $a=10; $b=11; echo $a>$b; //return false because $a is less than $b. echo $a<$b; //return true because $a is less than $b. echo $a>=$b; //return false because neighter $a is greater nor equal to $b echo $a<=$b; //return true because $a is than $b. ?>