Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Conditional Statements

What will be the output of this PHP code?

<?php
$x = 10;
if ($x > 5) {
  if ($x < 15) {
    echo 'Inside nested if';
  } else {
    echo 'Inside else';
  }
} else {
  echo 'Outside if';
}
?>
AInside nested if
BInside else
COutside if
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate outer if condition

    $x is 10, which is greater than 5, so outer if is true.
  2. Step 2: Evaluate inner if condition

    10 is less than 15, so inner if is true, printing 'Inside nested if'.
  3. Final Answer:

    Inside nested if -> Option A
  4. Quick Check:

    Nested if true conditions print inner message [OK]
Quick Trick: Check outer if first, then inner if conditions [OK]
Common Mistakes:
  • Ignoring inner if condition
  • Confusing else blocks
  • Assuming no output if inner false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes