Bird
0
0

What is the correct way to access the first element of an array $arr in PHP?

easy📝 Conceptual Q11 of 15
PHP - Arrays
What is the correct way to access the first element of an array $arr in PHP?
A$arr{0}
B$arr[1]
C$arr[0]
D$arr->0
Step-by-Step Solution
Solution:
  1. Step 1: Understand PHP array indexing

    PHP arrays start at index 0, so the first element is at index 0.
  2. Step 2: Identify correct syntax for array access

    Use square brackets with the index number: $arr[0].
  3. Final Answer:

    $arr[0] -> Option C
  4. Quick Check:

    First element index = 0 [OK]
Quick Trick: First element is always at index 0 in PHP arrays [OK]
Common Mistakes:
  • Using index 1 for first element
  • Using curly braces for array access
  • Using object property syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes