Google News
logo
PHP Program to Logical or Relational Operators
Here's an example PHP program that demonstrates the use of logical and relational operators :
Program :
<?php

$a = 10;
$b = 5;

// 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>";
}

// 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>";
}

// Logical AND operator
if ($a > 0 && $b > 0) {
    echo "$a and $b are both positive numbers <br>";
}

// Logical OR operator
if ($a > 0 || $b > 0) {
    echo "$a or $b is a positive number <br>";
}

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

?>
Output :
10 is greater than 5 
10 is greater than or equal to 5 
10 is not equal to 5 
10 and 5 are both positive numbers 
10 or 5 is a positive number 
10 is not 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 relational operators to compare the values of `$a` and `$b` and use logical operators to combine the results. Finally, we print out the results using the `echo` statement.