Bird
0
0

Which of the following is the correct syntax to add an element 'apple' to the array $fruits using array_push?

easy📝 Syntax Q12 of 15
PHP - Arrays
Which of the following is the correct syntax to add an element 'apple' to the array $fruits using array_push?
Aarray_push('apple', $fruits);
Barray_push($fruits['apple']);
Carray_push($fruits => 'apple');
Darray_push($fruits, 'apple');
Step-by-Step Solution
Solution:
  1. Step 1: Recall the function signature

    The correct syntax is array_push(array, value1, value2, ...), where the first argument is the array variable.
  2. Step 2: Check each option

    array_push($fruits, 'apple'); correctly uses array_push($fruits, 'apple');. Others misuse argument order or syntax.
  3. Final Answer:

    array_push($fruits, 'apple'); -> Option D
  4. Quick Check:

    array_push(array, value) syntax [OK]
Quick Trick: First argument is array, then values to add [OK]
Common Mistakes:
  • Swapping argument order
  • Using arrow => instead of comma
  • Passing only one argument incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes