Bird
0
0

Which of the following correctly creates an indexed array with three elements in PHP?

easy📝 Conceptual Q11 of 15
PHP - Arrays
Which of the following correctly creates an indexed array with three elements in PHP?
A<code>$arr = ["apple", "banana", "cherry"];</code>
B<code>$arr = {"apple", "banana", "cherry"};</code>
C<code>$arr = ("apple", "banana", "cherry");</code>
D<code>$arr = array:"apple", "banana", "cherry";</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recognize PHP array syntax

    PHP indexed arrays can be created using square brackets [] or the array() function.
  2. Step 2: Check each option's syntax

    $arr = ["apple", "banana", "cherry"]; uses [] with comma-separated values, which is correct. Options A, B, and C use invalid syntax for arrays.
  3. Final Answer:

    $arr = ["apple", "banana", "cherry"]; -> Option A
  4. Quick Check:

    Correct array syntax = $arr = ["apple", "banana", "cherry"]; [OK]
Quick Trick: Use square brackets [] or array() to create indexed arrays [OK]
Common Mistakes:
  • Using curly braces {} instead of []
  • Using parentheses () without array()
  • Incorrect use of colons or other symbols

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes