PHP - array_shift
Trieda
Metóda - array_shift
(PHP 4, PHP 5, PHP 7)
Removes the first element from an array and moves others forward. The
function allows using the array as a queue, so it should only be used in the
code if we work with the array as a queue. Otherwise, we remove the last element
with an unset() function.
Numerical indexes will be renumbered from zero. The function resets an internal pointer to the current element in the array.
Procedurálne
- function array_shift (array &$array) : mixed
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| &$array | array | The array (queue). |
Mávratovej hodnoty
Vracia: mixed
The removed element or NULL on failure.
Príklady
<?php
$queue = ['Homer', 'Marge', 'Bart', 'Lisa', 'Meggie'];
$simpson = array_shift($queue);
print_r($queue);
echo $simpson;
Súvisiace manuály
- function array_pop (array &$array) : mixed
- function array_push (array &$array, mixed $value1, mixed $...) : int
- function array_unshift (array &$array, mixed $value1, mixed $...) : int
