NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - array_shift

Trieda

Koreň \ Bez triedy

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

Parametre

NázovDátový typPredvolená hodnotaPopis
&$arrayarray

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
      Aktivity