Skip to content

PHP Else Statement

The else statement in PHP allows you to execute a block of code when the condition in the if statement is not met.

Syntax

// Generic version of an if-else statement
if (condition) {
// Code to execute if the condition is true
} else {
// Code to execute if the condition is false
}

Example

// Concrete example of an if statement
$age = 16;
if ($age >= 18) {
echo "You are eligible to vote.";
} else {
echo "You are not eligible to vote.";
}
// Output: You are not eligible to vote.