Backend Development 2 min read

array_push() – Push One or More Elements onto the End of an Array (Stack)

The article explains PHP's array_push() function, describing how it treats an array as a stack, details its parameters and return value, and provides a complete example with code and output demonstrating how to push multiple elements onto an array.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
array_push() – Push One or More Elements onto the End of an Array (Stack)

array_push() treats an array as a stack and pushes one or more values onto the end of the array, increasing its length accordingly.

Parameters

array – The input array.

var – The value(s) to be pushed onto the array.

Return value

Returns the number of elements in the array after the push operation.

Example

Output

Array
(
    [0] => orange
    [1] => banana
    [2] => apple
    [3] => raspberry
)
backendPHPTutorialfunctionsarraysarray_push
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.