Operators


Comparison Operators

The result of comparison operators is always Boolean type.

Operator Sign Syntax Additional Information
Equal
(value)
== $var1 == $var2 TRUE if $var1 is equal to $var2
Identical
(value+type)
=== $var1 === $var2 TRUE if $var1 is equal to $var2
and they are of the same type
Not equal
(value)
!= $var1 != $var2 TRUE if $var1 is not equal to $var2
Not identical
(value+type)
!== $var1 !== $var2 TRUE if $var1 is not equal to $var2
or they are not of the same type
Not equal
(value)
<> $var1 <> $var2 TRUE if $var1 is not equal to $var2
Less than < $var1 < $var2 TRUE if $var1 is strictly less than $var2
Greater than > $var1 > $var2 TRUE if $var1 is strictly greater
than $var2
Less than
or equal to
<= $var1 <= $var2 TRUE if $var1 is strictly less
than or equal to $var2
Greater than
or equal to
>= $var1 >= $var2 TRUE if $var1 is strictly greater
than or equal to $var2
<?php
    $var1 = 1;
    $var2 = 2;
    $var3 = $var1 == $var2;    // $var3 = False (0 - False)
    $var4 = $var1 != $var2;    // $var4 = True (1 - True)
    $var5 = $var1 <> $var2;    // $var5 = True (1 - True)
    $var6 = $var1 < $var2;     // $var6 = True (1 - True)
    $var7 = $var1 > $var2;     // $var7 = False (0 - False)
    $var8 = $var1 <= $var2;    // $var8 = True (1 - True)
    $var9 = $var1 >= $var2;    // $var9 = False (0 - False)
?>