Breaking News

PHP-MySQLi Series 5.3 || comparison operators





Comparison Operators:

It is used to compare the two values.





These operators test two values against each other, If they match with each other, it display TRUE result. If it is false, it will display else statement in php.



All comparison operators take two values for input.

Some examples:
Equal (==) operator
<?php
$x = 25;
$y = 25;
if ($x == $y){
echo "TRUE";}
else {echo "FALSE";}
?>
Solution: In this condition, the value of x is equal to value of y. It will print TRUE.

Identical operator (===)
<?php
$x = 25;
$y = '25';
if ($x === $y){
echo "TRUE";}
else {echo "FALSE";}
?>
Solution: In this condition, the value of x is not equal to value of y because x have number value where as y have string value. It will print FALSE.

Not equal Operator (!=)
<?php
$x = 25;
$y = 25;
if ($x != $y){
echo "TRUE";}
else {echo "FALSE";}
?>
Solution: In this condition, the value of x is equal to value of y. It will print FALSE.


Operators

Name

Example

Result

==

Equal

$x == $y

TRUE, if $x is equl to $y.

===

Identical

$x===$y

TRUE, if $x is identical to $y, but the
value must be same type.

!==

Not identical

$x!=$y

TRUE, if $x is not identical to $y.

!= / <>

Not equal

$x!=$y

TRUE, if $x is not equal to $y.

< 

Less than  

$x < $y

TRUE, if $x value is less than to $y value.

> 

Greater than

$x < $y

TRUE, if $x value is greater than to $y
value.

<=

Less than or equal to

$x <= $y

TRUE, if $x value is less than or equal to
$y.

>=

Greater than or equal to

$x >= $y

TRUE, if $x value is greater than or equal
to $y.

No comments