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_unshift

Trieda

Koreň \ Bez triedy

Metóda - array_unshift

(PHP 4, PHP 5, PHP 7)

Prepends one or more elements to the front of an array. The function allows you to use the array as a queue, so it should only be used if we work with the array as a queue.

Numerical indexes will be renumbered from 0. The function resets an internal pointer to the current element in the array.

Procedurálne

  • function array_unshift (array &$array, mixed $value1, mixed $...) : int

Parametre

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

An array (queue).

$value1mixed

A value to prepend.

$...mixed

Additional values to prepend.

Mávratovej hodnoty

Vracia: int

The number of new elements in the queue.

Príklady

<?php
$queue =['Marge', 'Bart', 'Lisa', 'Meggie'];
array_unshift($queue, 'Homer');

print_r($queue);

Súvisiace manuály

      • function array_pop (array &$array) : mixed
      • function array_push (array &$array, mixed $value1, mixed $...) : int
      • function array_shift (array &$array) : mixed
      Aktivity