Bird
0
0

Which of the following is the correct syntax to create an indexed array with the elements 10, 20, and 30 in PHP?

easy📝 Syntax Q12 of 15
PHP - Arrays
Which of the following is the correct syntax to create an indexed array with the elements 10, 20, and 30 in PHP?
A<code>$numbers = [10; 20; 30];</code>
B<code>$numbers = array(10, 20, 30);</code>
C<code>$numbers = (10, 20, 30);</code>
D<code>$numbers = {10, 20, 30};</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP array creation syntax

    PHP allows creating arrays using array() with parentheses and comma-separated values.
  2. Step 2: Validate each option

    $numbers = array(10, 20, 30); uses array() correctly. Options B, C, and D use invalid separators or brackets.
  3. Final Answer:

    $numbers = array(10, 20, 30); -> Option B
  4. Quick Check:

    array() with commas = $numbers = array(10, 20, 30); [OK]
Quick Trick: Use commas inside array() or [] to separate elements [OK]
Common Mistakes:
  • Using semicolons instead of commas
  • Using parentheses without array()
  • Using curly braces for arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes