array_pop()
Published Jul 8, 2023
Contribute to Docs
The array_pop()
method removes the last element of an array, and returns the truncated array.
Syntax
array_pop($array)
The array_pop()
function has one required parameter, $array
, which specifies the input array
.
If the specified array is empty, null will be returned.
Example
The following example uses the array_pop()
function to remove "Mexico"
from the array $countries
:
<?php$countries = array("USA","Canada","England","Mexico");array_pop($countries);print_r($countries);?>
The example will result in the following output:
Array ([0] => USA[1] => Canada[2] => England)
Codebyte Example
This example is runnable and uses the array_pop()
function:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.