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.
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
)Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
