if...else
statements in PHP allow conditional execution of code based on different conditions.
true
)$age = 18;
if ($age >= 18) {
echo "You are eligible to vote.";
}
✔ If $age
is 18
or more, it prints "You are eligible to vote."
2️⃣ if...else Statement (Executes one block if true
, another if false
)
$age = 16;
if ($age >= 18) {
echo "You can vote.";
} else {
echo "You are too young to vote.";
}
✔ If $age
is 16
, the else block runs.