Bird
0
0

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

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

    The correct syntax is array_push(array, value1, value2, ...).
  2. Step 2: Check each option

    array_push($fruits, 'banana'); correctly uses array_push with $fruits and 'banana' as arguments.
  3. Final Answer:

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

    Correct syntax = array_push(array, value) [OK]
Quick Trick: array_push(array, 'value') adds value at end [OK]
Common Mistakes:
  • Swapping argument order
  • Missing quotes around string
  • Using array_push with only one argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes