Array Functions

PHP array_pop() Function

Topic: PHP Array ReferencePrev|Next


The array_pop() function removes the last element of an array.

The following table summarizes the technical details of this function.

Return Value: Returns the value of the last element of array.
If array is empty or is not an array, NULL will be returned.
Version: PHP 4+


The basic syntax of the array_pop() function is given with:


The following example shows the array_pop() function in action.

// Sample array
$cities = array("London", "Paris", "New York", "Sydney");
// Remove and get the last value from array
echo array_pop($cities); // Prints: Sydney


The array_pop() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to get the last value from.

More Examples

Here're some more examples showing how array_pop() function actually works:

This function can also be used with the associative array, as shown here:

// Sample array
$alphabets = array("a"=>"apple", "b"=>"ball", "c"=>"cat", "d"=>"dog");
// Remove and get the last value from array
echo array_pop($alphabets); // Prints: dog
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties