PHP array pop

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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.

Pictorial Presentation :

php array array_pop() function

Example :

  1. $array1= array('Mathematics','Physics','Chemistry','Biology');  

  2. $subject=array_pop($array1);  

  3. print_r($array1);  

  4. ?>  

Output :

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