Bird
0
0

Find the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Conditional Statements
Find the error in this PHP code:
if $x > 10 {
    echo "Big";
} else {
    echo "Small";
}
AVariable $x is not defined
BMissing parentheses around the condition
CIncorrect use of else keyword
DMissing semicolon after echo statements
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for if statement

    PHP requires parentheses around the condition in an if statement.
  2. Step 2: Identify the missing parentheses

    The code misses parentheses around $x > 10, causing a syntax error.
  3. Final Answer:

    Missing parentheses around the condition -> Option B
  4. Quick Check:

    If condition must be in parentheses [OK]
Quick Trick: Always use parentheses around if conditions [OK]
Common Mistakes:
  • Forgetting parentheses around condition
  • Assuming semicolons needed after echo inside braces
  • Thinking else keyword is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes