PHP array_push() Function
Last Updated : 17 Mar 2025
The array_push() function is a inbuilt function in PHP. The array_push() function is used to add one or more elements onto the end of an array. The length of array increases by the number of variables pushed. The array_push() function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Required/Optional |
|---|---|---|
| array | Specifies an array. | compulsory |
| Value1 | Specifies the value to add. | compulsory |
| Value2 | Specifies the value to add. | Optional |
Return Type
The array_push() function returns the new number of elements in the array.
Example 1
Output:
Array
(
[a] =>php
[b] => java
[0] =>laravel
[1] =>bluej
)
Example 2
Output:
Array
(
[0] =>tata
[1] =>honda
[2] =>nexon
[3] => city
)
Example 3
Output:
Array
(
[0] => c
[1] => java
[2] =>os
[3] => compiler
)
Example 4
Output:
Array
(
[a] => apple
[b] => ball
[0] => cat
[1] => dog
)
Next TopicPhp-array-rand-function