PHP If Operators

PHP provides several if operators for conditional statements.

if Operator

The if operator is used to execute a block of code if a condition is true.

elseif Operator

The elseif operator is used to check another condition if the initial condition is false.

else Operator

The else operator is used to execute a block of code if all conditions are false.

Example of PHP If Operators

<?php
$x = 10;
if ($x > 5) {
    echo "x is greater than 5";
} elseif ($x == 5) {
    echo "x is equal to 5";
} else {
    echo "x is less than 5";
}
?>

Output:

x is greater than 5

Explanation: This example demonstrates the use of if, elseif, and else operators in PHP.