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

<?php
$stack = array("orange","banana");
array_push($stack, "apple","raspberry");
print_r($stack);
?>

Output

Array
(
    [0] => orange
    [1] => banana
    [2] => apple
    [3] => raspberry
)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendTutorialfunctionsArraysarray_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

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.