Skip to content
AgileLogics
4 min read

Conditionals

Prerequisites: Constants

Syntax

if ($age >= 18) {
    echo "Adult";
} elseif ($age >= 13) {
    echo "Teenager";
} else {
    echo "Child";
}

Example

$temperature = 15;
if ($temperature > 30) {
    echo "Hot";
} elseif ($temperature > 15) {
    echo "Mild";
} else {
    echo "Cold";
}

Expected output

Cold

Practice

Write a condition that prints "Pass" if $score is 50 or above, otherwise "Fail".

Show solution
$score = 42;
if ($score >= 50) {
    echo "Pass";
} else {
    echo "Fail";
}