Bird
0
0

Which of the following is the correct way to access the element 'blue' in this array?

easy📝 Syntax Q12 of 15
PHP - Arrays
Which of the following is the correct way to access the element 'blue' in this array?
$colors = [['red', 'green'], ['blue', 'yellow']];
A$colors[1][0]
B$colors[0][2]
C$colors[2][1]
D$colors[1][1]
Step-by-Step Solution
Solution:
  1. Step 1: Identify the position of 'blue'

    'blue' is in the second inner array (index 1) and is the first element (index 0) there.
  2. Step 2: Use correct indices to access

    Accessing $colors[1][0] retrieves 'blue'. Other options point to wrong indices or elements.
  3. Final Answer:

    $colors[1][0] -> Option A
  4. Quick Check:

    Second array, first element = 'blue' [OK]
Quick Trick: Count arrays and elements starting at zero [OK]
Common Mistakes:
  • Using wrong index numbers
  • Confusing first and second arrays
  • Trying to access non-existing elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes