Which function is used to add an item to the end of an array?
A
array_push() B
array_pop() C
array_shift() D
array_unset()
Analysis & Theory
`array_push()` adds one or more items to the end of an array.
Which function removes the last item from an array?
A
array_push() B
array_shift() C
array_pop() D
array_remove()
Analysis & Theory
`array_pop()` removes the last element from an array.
Which function removes the first item from an array?
A
array_shift() B
array_pop() C
array_unset() D
array_remove()
Analysis & Theory
`array_shift()` removes the first element from an array.
Which function is used to add an item to the beginning of an array?
A
array_push() B
array_unshift() C
array_shift() D
array_pop()
Analysis & Theory
`array_unshift()` adds one or more items to the beginning of an array.
What is the output?
```
<?php
$fruits = array('apple', 'banana');
array_push($fruits, 'cherry');
print_r($fruits);
?>
```
A
Array ( [0] => apple [1] => banana [2] => cherry ) B
Array ( [0] => cherry [1] => apple [2] => banana ) C
Array ( [0] => apple [1] => cherry ) D
Error
Analysis & Theory
`array_push()` adds `'cherry'` to the end of the array.
How do you remove a specific item from an associative array with key 'name'?
A
remove($array['name']); B
unset($array['name']); C
delete($array['name']); D
array_pop($array, 'name');
Analysis & Theory
`unset($array['name']);` removes the item with key `'name'` from the array.
What is the output after this code?
```
<?php
$colors = array('red', 'green', 'blue');
array_shift($colors);
print_r($colors);
?>
```
A
Array ( [0] => green [1] => blue ) B
Array ( [0] => red [1] => green ) C
Array ( [0] => blue [1] => green ) D
Error
Analysis & Theory
`array_shift()` removes the first item `'red'`. The remaining array is `'green'` and `'blue'`.
What does the `unset()` function do in arrays?
A
Deletes an array completely B
Removes a specific key/value pair from the array C
Clears the entire array D
Adds an item to the array
Analysis & Theory
`unset()` removes a specific element from an array based on its key.
Which function can add multiple items to the beginning of an array?
A
array_shift() B
array_push() C
array_unshift() D
array_add()
Analysis & Theory
`array_unshift()` can add one or more items to the beginning of an array.
What happens if you use `array_pop()` on an empty array?
A
Returns NULL B
Causes an error C
Returns 0 D
Adds a new item
Analysis & Theory
If the array is empty, `array_pop()` returns `NULL` without an error.