Skip to content

PHP Elseif Statement

Syntax

The elseif statement in PHP is used to specify additional conditions to check after an initial if condition fails.

if (condition1) {
// Code to execute if condition1 is true
} elseif (condition2) {
// Code to execute if condition2 is true
} else {
// Code to execute if none of the above conditions are true
}

Example

$age = 19;
if ($age < 13) {
echo "You are a child.";
} elseif ($age < 20) {
echo "You are a teenager.";
} else {
echo "You are an adult.";
}
// Output: You are a teenager.