Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Arrays
Identify the error in this PHP code:
$arr = [1, 2, 3;
echo $arr[0];
AArray keys must be strings
BMissing semicolon after echo statement
CMissing closing bracket "]" in array declaration
DUsing parentheses instead of square brackets
Step-by-Step Solution
Solution:
  1. Step 1: Check array syntax

    The array declaration uses [1, 2, 3; which is missing the closing "]" bracket.
  2. Step 2: Identify syntax error

    Without the closing bracket, PHP will throw a syntax error.
  3. Final Answer:

    Missing closing bracket "]" in array declaration -> Option C
  4. Quick Check:

    Array syntax error = Missing closing bracket "]" in array declaration [OK]
Quick Trick: Always close arrays with matching brackets [] [OK]
Common Mistakes:
  • Forgetting closing bracket
  • Confusing semicolon placement
  • Thinking keys must be strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes