Bird
0
0

Which of the following creates an indexed array with the elements "red", "green", and "blue"?

easy📝 Conceptual Q2 of 15
PHP - Arrays
Which of the following creates an indexed array with the elements "red", "green", and "blue"?
A$colors = <"red", "green", "blue">;
B$colors = {"red", "green", "blue"};
C$colors = ("red", "green", "blue");
D$colors = array("red", "green", "blue");
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP array creation functions

    PHP supports array creation using the array() function or square brackets [].
  2. Step 2: Identify valid syntax

    The syntax $colors = array("red", "green", "blue"); correctly creates an indexed array with three string elements.
  3. Final Answer:

    $colors = array("red", "green", "blue"); -> Option D
  4. Quick Check:

    Indexed array creation with array() = $colors = array("red", "green", "blue"); [OK]
Quick Trick: Use array() or [] to create arrays in PHP [OK]
Common Mistakes:
  • Using curly braces {} which are invalid for arrays
  • Using parentheses () without array keyword
  • Using angle brackets <> which are invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes