PHP array_push function
Last Updated: February 14, 2022
array_push- push one or more elements onto the top of the array.
Syntax
array_push(array &$array, mixed ...$values): int
Supports (PHP 4, PHP 5, PHP 7, PHP 8)
Parameters
Parameter | Description |
array | Required. target array |
values | Required. values to push onto the array |
Return Value
returns the new number of elements of the array
Example
<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>
Output
Array
(
[0] => orange
[1] => banana
[2] => apple
[3] => raspberry
)