Bird
0
0

Identify the syntax error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Basics and Execution Model
Identify the syntax error in this PHP code:
<?php
for ($i = 0; $i < 3; $i++) {
echo $i
}
AMissing semicolon after echo statement
BIncorrect for loop syntax
CBraces should be parentheses
DVariable $i is not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Review echo statement

    In PHP, each statement must end with a semicolon.
  2. Step 2: Check the code

    The echo statement lacks a semicolon after $i.
  3. Final Answer:

    Missing semicolon after echo statement -> Option A
  4. Quick Check:

    Statements need semicolons [OK]
Quick Trick: Always end PHP statements with semicolons [OK]
Common Mistakes:
  • Omitting semicolons after statements
  • Confusing braces with parentheses
  • Assuming variables need declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes