Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q14 of 15
PHP - Basics and Execution Model
Identify the error in this PHP code:
$count = 5
if ($count > 3) {
echo 'Count is greater than 3';
}
Aecho statement should be outside if block
BIncorrect if statement syntax
CMissing semicolon after $count = 5
DVariable $count is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check variable assignment syntax

    In PHP, each statement must end with a semicolon. The line $count = 5 is missing it.
  2. Step 2: Verify if statement and echo syntax

    The if statement and echo are correctly written with proper braces and syntax.
  3. Final Answer:

    Missing semicolon after $count = 5 -> Option C
  4. Quick Check:

    Statements need semicolons = A [OK]
Quick Trick: Always end PHP statements with semicolon [OK]
Common Mistakes:
  • Forgetting semicolon after variable assignment
  • Misplacing braces in if statement
  • Thinking echo must be outside if block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes