Bird
0
0

Identify the mistake in this PHP code snippet:

medium📝 Debug Q6 of 15
PHP - Arrays
Identify the mistake in this PHP code snippet:
$list = array('a', 'b', 'c');
echo $list{1};
AMissing semicolon after array declaration
BUsing array() function to create the array
CUsing curly braces {} to access array elements
DUsing single quotes for array elements
Step-by-Step Solution
Solution:
  1. Step 1: Review array element access syntax

    In PHP, array elements are accessed using square brackets [].
  2. Step 2: Identify incorrect usage

    The code uses curly braces {} which is invalid for arrays (used for strings in older PHP versions).
  3. Final Answer:

    Using curly braces {} to access array elements -> Option C
  4. Quick Check:

    Always use square brackets [] for arrays. [OK]
Quick Trick: Access arrays with [] not {} [OK]
Common Mistakes:
  • Confusing string access syntax with arrays
  • Using parentheses () instead of brackets
  • Assuming array() is deprecated (it's valid)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes