Bird
0
0

Which of the following is the correct way to create an array in PHP?

easy📝 Syntax Q12 of 15
PHP - Arrays
Which of the following is the correct way to create an array in PHP?
A$arr = array(1, 2, 3);
B$arr = {1, 2, 3};
C$arr = [1; 2; 3];
D$arr = (1, 2, 3);
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP array syntax

    In PHP, arrays can be created using the array() function or square brackets []. The syntax array(1, 2, 3) is correct.
  2. Step 2: Check each option

    $arr = array(1, 2, 3); uses array() correctly. The other options use invalid syntax: curly braces {}, semicolons between elements, and parentheses without array keyword.
  3. Final Answer:

    $arr = array(1, 2, 3); -> Option A
  4. Quick Check:

    array() syntax = A [OK]
Quick Trick: Use array() or [] to create arrays [OK]
Common Mistakes:
  • Using curly braces {} for arrays
  • Separating elements with semicolons
  • Using parentheses () without array keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes