Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


The PHP Array array_pop() function is used to delete the last element of the given array. The function returns the value of the last element (deleted element) of the array.

Syntax

array_pop(array)

Parameters

array Required. Specify an array.

Return Value

Returns the value of the last element of array. If array is empty (or is not an array), null will be returned.

Exceptions

throws E_WARNING, if the function is called on a non-array.

Example:

The below example shows the usage of array_pop() function.

<?php
$Arr = array(10, 20, 30, 40);

//deleting the last element of the array
array_pop($Arr);

print_r($Arr);
?>

The output of the above code will be:

Array
(
    [0] => 10
    [1] => 20
    [2] => 30
)

Example:

In the below example shows the usage of array_pop() function with an associative array.

<?php
$Arr = array("Marry"=>25, "John"=>30, "Jo"=>45, "Kim"=>22);

//deleting the last element of the array
array_pop($Arr);

print_r($Arr);
?>

The output of the above code will be:

Array
(
    [Marry] => 25
    [John] => 30
    [Jo] => 45
)

❮ PHP Array functions