w3resource

PHP: array_pop() function

PHP: Pop the element off the end of array

The array_pop() function is used to remove the last element of an array. For an empty array, the function returns NULL.

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

Version:

(PHP 4 and above)

Syntax:

array_pop(array_name) 

Parameter:

Name Description Required /
Optional
Type
array_pop The specified array whose last element will be removed. Required Array

Return value:

The last value of array_pop.

Value Type: Mixed*.

*Mixed: Mixed indicates multiple (but not necessarily all) types.

Example:

<?php
$array1= array('Mathematics','Physics','Chemistry','Biology');
$subject=array_pop($array1);
print_r($array1);
?>

Output:

Array ( [0] => Mathematics [1] => Physics [2] => Chemistry )

Pictorial Presentation:

php function reference: array_pop() function

View the example in the browser

Practice here online :

See also

PHP Function Reference

Previous: array_pad
Next: array_push



PHP: Tips of the Day

PHP: Extract numbers from a string

$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);