Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q5 of 15
PHP - Conditional Statements

What will be the output of the following PHP code?

<?php
$temperature = 65;
if ($temperature >= 80) {
    echo "Hot";
} elseif ($temperature >= 60) {
    echo "Warm";
} elseif ($temperature >= 40) {
    echo "Cool";
} else {
    echo "Cold";
}
?>
AHot
BCool
CWarm
DCold
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate first condition

    $temperature = 65 is not ≥ 80, so skip first block.
  2. Step 2: Evaluate second condition

    65 ≥ 60 is true, so echo "Warm" and skip remaining conditions.
  3. Final Answer:

    Warm -> Option C
  4. Quick Check:

    First true condition executes only [OK]
Quick Trick: Only first true elseif block runs [OK]
Common Mistakes:
  • Assuming multiple blocks run if conditions are true
  • Misreading comparison operators
  • Ignoring else block when earlier condition is true

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes