PHP - array_push
Trieda
Metóda - array_push
(PHP 4, PHP 5, PHP 7)
Inserts an element into an array after the last element. The function allows you to use the array as a stack, so it should only be used if we work with the array as a stack.
Otherwise, we insert the last element using $array[] = $element;
The function resets the internal pointer to the current element in the
array.
Procedurálne
- function array_push (array &$array, mixed $value1, mixed $...) : int
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| &$array | array | An array (stack). If the parameter is not the array, it throws a warning. | |
| $value1 | mixed | An inserted element. | |
| $... | mixed | An additional element to insert. |
Mávratovej hodnoty
Vracia: int
A new number of elements in the array.
Príklady
<?php
$stack= ['Homer', 'Marge', 'Bart', 'Lisa'];
array_push($stack, 'Meggie');
print_r($stack);
Súvisiace manuály
- function array_pop (array &$array) : mixed
- function array_shift (array &$array) : mixed
- function array_unshift (array &$array, mixed $value1, mixed $...) : int
