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 = 30;
if ($temperature >= 35) {
  echo 'Hot';
} else {
  if ($temperature >= 25) {
    echo 'Warm';
  } else {
    echo 'Cold';
  }
}
?>
AHot
BWarm
CCold
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate first condition

    $temperature is 30, which is not >= 35, so skip first if block.
  2. Step 2: Evaluate nested condition

    30 is >= 25, so the nested if block executes, printing 'Warm'.
  3. Final Answer:

    Warm -> Option B
  4. Quick Check:

    Check conditions in order; nested if runs only if outer if is false. [OK]
Quick Trick: Check outer if first, then nested if [OK]
Common Mistakes:
  • Assuming both if blocks run simultaneously
  • Confusing else placement
  • Ignoring nested condition evaluation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes