Adds elements to the end of an array.
With array_push(), one or more elements can be added to the end of an array. The number of elements that were added is returned.
An array can be used as a stack by using array_push() and array_pop() together.
<?php
$array1[] = "orange";
array_push($array1, "apple", "banana", "pear");
for ($i = 0; $i < 4; $i++) {
print array_pop($array1) . " " . sizeof($array1) . "<br>";
}
?>
pear 3
banana 2
apple 1
orange 0
A few elements are pushed into an array with array_push(). Each element is then printed as it is popped, together with the size of the remaining array. Note that the elements are printed in reverse order.