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:
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.
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.
Final Answer:
$arr = array(1, 2, 3); -> Option A
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
Master "Arrays" in PHP
9 interactive learning modes - each teaches the same concept differently