PHP array_push() Function

6 Jan 2025 | 1 min read

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

ParameterDescriptionRequired/Optional
arraySpecifies an array.compulsory
Value1Specifies the value to add.compulsory
Value2Specifies 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 )