Saturday, May 5, 2012

array_pop and array_push in PHP

array_push  Push one or more elements onto the end of array

array_push() treats array as a stack, and pushes the passed variables onto the end of array. The length of array increases by the number of variables pushed.

Has the same effect as:

$array[] = $var;
repeated for each var.

array_pop  Pop the element off the end of array

array_pop() pops and returns the last value of the array, shortening the array by one element. If array is empty (or is not an array), NULL will be returned. Will additionally produce a Warning when called on a non-array.

Note: This function will reset() the array pointer of the input array after use.