PHP Comparison Operators

PHP Comparison operators are used to compare the values of two elements and return a boolean result. Comparison operators supported by PHP are ==,!=,<,>,<=,>=.

Operator Name example Description
== Equal to $m == $n It will return true if both operands[$m and $n] are equal.
!=, <> Not equal to $m != $n It will return true if both operands[$m and $n] are not equal.
=== Identical to $m === $n It will return true if both operands[$m and $n] are equal and exact same type.
!== Not identical to $m !== $n It will return true if both operands[$m and $n] are not equal or exact same type.
> Greater than $m < $n It will return true if $m is less than $n.
>= Greater than or equal to $m > $n It will return true if $m is greater than $n.
< Less than $m <= $n IIt will return true if $m is less than or equal to $n
<= Less than or equal to $m >= $n It will return true if $m is greater than or equal to $n

Equality Operator (==)

It will return true if both operands are equal. else it will return false. in the following example, $m is equal to $n.Hence TRUE is returned.
			

<?php
$m = 200;  
$n = "200";

var_dump($m == $n); // it will return true because values are equal
?> 

				

Output:

bool(true)