Conditional Statements: if, else, elseif
Control program flow using if, else, and elseif statements in PHP.
Laura Bennett
November 6, 2025
3.2k109
Conditions let your program make decisions.
Basic if statement
$score = 75;
if ($score >= 50) {
echo "You passed!";
}
if...else
if ($score >= 50) {
echo "Pass";
} else {
echo "Fail";
}
if...elseif...else
if ($score >= 90) {
echo "Grade A";
} elseif ($score >= 70) {
echo "Grade B";
} else {
echo "Grade C";
}
Ternary operator
$result = ($score >= 50) ? "Pass" : "Fail";
Next: Loops to repeat work.
#PHP#Conditions#Beginner