array_push() and array_pop() functions are used to push and pop elements on a array. These functions have the following syntax:
array_push($array,$element);
$element = array_pop($array);
Lets look at the following code:
$mya = array(0 => "zero",1 => "one",2 => "two");
array_push($mya, "three");
$mya[] = "four";
print_r($mya);
This program would produce the following results. array_push() adds an element at the end of the array. The code on the last line is equivalent to a pop.
Array
(
[0] => zero
[1] => one
[2] => two
[3] => three
[4] => four
)
array_pop removes the last element from an array. Let's look at the following program:
$mya = array(0 => "zero",1 => "one",2 => "two");
$n = array_pop($mya);
print "$n\n";
print_r($mya);
This program produces the following result.
two
Array
(
[0] => zero
[1] => one
)