We can compare values of two operants (variables) using
Comparison operators.
Comparison Opearators List
== : Equal to
=== : Identical
<> : Not equal
!= : Not equal
!== : Not identical
< : Less than
<= : Less than equal to
> : Greater than
>= : Greater than or equal to
Syntax :
boolean operant1 OPERATOR operant2
Example : Equal to Operator
<?php
$a = 5;
$b = 5;
echo var_dump($a == $b);
}
?>
Output
bool(true)
Example : Identical
<?php
$a = 5;
$b = 2;
echo var_dump($a === $b);
}
?>
Output
bool(false)
Example : No Equal to
<?php
$a = 5;
$b = 2;
echo var_dump($a != $b);
echo var_dump($a <> $b);
}
?>
Output
bool(true)
bool(true)
Example : No Identical
<?php
$a = 5;
$b = 2;
echo var_dump($a !== $b);
}
?>
Output
bool(true)
Example : Less than
<?php
$a = 5;
$b = 2;
echo var_dump($a < $b);
}
?>
Output
bool(false)
Example : Less than equal to
<?php
$a = 2;
$b = 5;
echo var_dump($a <= $b);
}
?>
Output
bool(true)
Example : Greater than
<?php
$a = 2;
$b = 5;
echo var_dump($a > $b);
}
?>
Output
bool(false)
Example : Greater than equal to
<?php
$a = 2;
$b = 5;
echo var_dump($a >= $b);
}
?>
Output
bool(false)