Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Conditional Statements

What will be the output of the following PHP code?

<?php
$x = 5;
$y = 8;
if ($x > 3) {
    if ($y < 10) {
        echo "A";
    } else {
        echo "B";
    }
} else {
    echo "C";
}
?>
ANo output
BB
CA
DC
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate outer if condition

    $x = 5, which is greater than 3, so the outer if block runs.
  2. Step 2: Evaluate inner if condition

    $y = 8, which is less than 10, so the inner if block runs and prints "A".
  3. Final Answer:

    A -> Option C
  4. Quick Check:

    5 > 3 and 8 < 10 = A [OK]
Quick Trick: Check outer condition first, then inner [OK]
Common Mistakes:
  • Ignoring inner condition result
  • Confusing else blocks
  • Assuming else runs when condition is true

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes