Comparison Operators in PHP

Estudies4you
Comparison Operators in PHP

Comparison Operators

Comparison operators allow you to compare two values. Based on the result of comparison, the result is either TRUE or FALSE. The table below lists comparison operators along with description and examples.
In the examples below A = 10 and B = 20.

Comparison Operators in PHP

Example:
Script: Comparision_op.php
<html>
<head> <title>Comparision Operators</title> </head>
<body>
<?php
$a = 34;
$b = 45;
echo "a=".$a."</br>";
echo "b=".$b."</br>";
if( $a == $b ){ echo "Equality operator : a is equal to b<br/>";
}
Else
{
echo "Equality operator : a is not equal to b<br/>";
} else{
echo "Equality Operator : a is not equal to b<br/>";
}
if( $a > $b ){
echo "Greater than operator : a is greater than b<br/>";
} else {
echo "Greater than operator : a is not greater than b<br/>";
}
if( $a < $b ){ echo "Less than operator : a is less than b<br/>";
} else {

echo "Less than operator : a is not less than b<br/>";
}
if( $a != $b ){
echo "Not Equal Operator : a is not equal to b<br/>";
} else{
echo "Not Equal Operator : a is equal to b<br/>";
}
if( $a >= $b ){
echo "Greater than or equal operator : a is either grater than or equal to b<br/>";
} else { 
echo "Greater than or equal operator : a is nieghter greater than nor equal to b<br/>";
}
if( $a <= $b echo "Less than or equal operator : a is either less than or equal to b<br/>";
} else {  
echo "Less than or equal operator : a is nieghter less than nor equal to b<br/>";
}
?>
</body>
</html>

OUTPUT:
A=34;
B=45;
Equality operator: a is not equal to b
Greater than operator: a is not greater than b
Less than operator: a is less than b
Not Equal Operator: a is not equal to b
Greater than or equal operator: a is neither greater than nor equal to b
Less than or equal operator: a is either less than or equal to b


To Top