Complete the code to add an element to the end of the array.
<?php $fruits = ['apple', 'banana']; array_[1]($fruits, 'orange'); print_r($fruits); ?>
The array_push function adds one or more elements to the end of an array.
Complete the code to remove the last element from the array and store it in a variable.
<?php $colors = ['red', 'green', 'blue']; $lastColor = array_[1]($colors); echo $lastColor; ?>
The array_pop function removes the last element from an array and returns it.
Fix the error in the code to correctly add 'pear' to the fruits array.
<?php $fruits = ['apple', 'banana']; array_[1]($fruits, 'pear'); print_r($fruits); ?>
The array_push function requires the array as the first argument, then the element(s) to add.
Fill both blanks to add 'kiwi' and then remove the last element from the array.
<?php $fruits = ['apple', 'banana']; array_[1]($fruits, 'kiwi'); $removed = array_[2]($fruits); echo $removed; ?>
First, array_push adds 'kiwi' to the end. Then, array_pop removes and returns the last element.
Fill all three blanks to add 'mango', remove the last element, and then add 'grape'.
<?php $fruits = ['apple', 'banana']; array_[1]($fruits, 'mango'); $removed = array_[2]($fruits); array_[3]($fruits, 'grape'); print_r($fruits); ?>
We add 'mango' with array_push, remove the last element with array_pop, then add 'grape' again with array_push.