Bird
0
0

What is wrong with this PHP code snippet?

medium📝 Debug Q6 of 15
PHP - Conditional Statements
What is wrong with this PHP code snippet?
if ($value > 20)
echo 'High';
echo 'Done';
APHP requires semicolon after if statement
BThe condition syntax is incorrect, missing parentheses
CThe variable $value is not defined
DThe second echo runs regardless of the if condition due to missing braces
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the if statement structure

    Without braces, only the first statement after if is controlled by it.
  2. Step 2: Identify effect on second echo

    Second echo runs always, which may be unintended.
  3. Final Answer:

    The second echo runs regardless of the if condition due to missing braces -> Option D
  4. Quick Check:

    Braces needed to group multiple statements [OK]
Quick Trick: Use braces to group multiple statements [OK]
Common Mistakes:
  • Assuming all statements are inside if without braces
  • Missing semicolon errors (not in this code)
  • Confusing syntax errors with logic errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes