Google News
logo
PHP Program to Comparison Operators
Here's an example PHP program that demonstrates the use of comparison operators :
Program :
<?php

$a = 10;
$b = 5;

// Equal to operator
if ($a == $b) {
    echo "$a is equal to $b <br>";
}

// Not equal to operator
if ($a != $b) {
    echo "$a is not equal to $b <br>";
}

// Identical operator
$a = "10";
if ($a === 10) {
    echo "$a is identical to 10 <br>";
} else {
    echo "$a is not identical to 10 <br>";
}

// Not identical operator
$a = "10";
if ($a !== 10) {
    echo "$a is not identical to 10 <br>";
}

// Greater than operator
if ($a > $b) {
    echo "$a is greater than $b <br>";
}

// Less than operator
if ($a < $b) {
    echo "$a is less than $b <br>";
}

// Greater than or equal to operator
if ($a >= $b) {
    echo "$a is greater than or equal to $b <br>";
}

// Less than or equal to operator
if ($a <= $b) {
    echo "$a is less than or equal to $b <br>";
}

?>
Output :
10 is not equal to 5
10 is not identical to 10
10 is not identical to 10
10 is greater than 5
10 is not less than 5
10 is greater than or equal to 5
10 is not less than or equal to 5
In this example, we have declared two variables `$a` and `$b` and assigned them the values `10` and `5`, respectively. We then use comparison operators to compare the values of `$a` and `$b`.

We also use the identical and not identical operators to compare the types of `$a` and `10`. Finally, we print out the results using the `echo` statement.