Bird
0
0

Find the error in this PHP code snippet:

medium📝 Debug Q7 of 15
PHP - Operators
Find the error in this PHP code snippet:
$x = 5;
$y = 10;
if ($x > $y) {
    echo 'x is greater';
} elseif ($x < $y) {
    echo 'y is greater';
} else
    echo 'Equal';
}
AIncorrect comparison operators
BMissing semicolon after echo statements
CExtra closing brace at the end
DNo error
Step-by-Step Solution
Solution:
  1. Step 1: Check braces balance

    There is an extra closing brace '}' after the else block which is not opened.
  2. Step 2: Confirm syntax correctness

    All other syntax including semicolons and operators are correct.
  3. Final Answer:

    Extra closing brace at the end -> Option C
  4. Quick Check:

    Brace mismatch causes syntax errors [OK]
Quick Trick: Match every opening brace with a closing brace [OK]
Common Mistakes:
  • Extra or missing braces
  • Missing semicolons
  • Wrong comparison operators
  • Incorrect else syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes