if, elseif, and else
Make decisions in PHP with conditional branching.
Conditional Logic in PHP
Conditional statements let your program make decisions. PHP provides if, elseif, and else for branching logic.
The condition inside if () is evaluated as a boolean — truthy proceeds into the block, falsy skips it.
Basic if Statement
The simplest conditional — run code only when a condition is true:
<?php
$age = 20;
if ($age >= 18) {
echo 'Adult';
}
// Output: AdultAll lessons in this course
- if, elseif, and else
- Switch and Match Statements
- for and while Loops
- foreach and Loop Control