To check the condition in PHP, if the condition is true, the code inside the if braces will execute.
If the condition is not true, it goes to the next and checks the condition.
If that condition is true, then the code inside the elseif braces runs.
If no condition is true, then the code inside the else braces runs.
Syntax:
if (condition1) {
// If condition1 is true then code executes.
} elseif (condition2) {
// If condition2 is true then code executes.
} else {
// If no conditions are true then code executes.
}
Example:
<?php
$number = 15;
if ($number > 20) {
echo "Number is bigger than 20";
} elseif ($number > 10) {
echo "Number is bigger than 10 but less than or equal to 20";
} else {
echo "Number is 10 or less";
}
?>
Output:
The number is bigger than 10 but less than or equal to 20
