This inbuilt function of PHP is used to delete or pop out and return the last element from an array passed to it as parameter. It reduces the size of the array by one since the last element is removed from the array.
Parameters: The function takes only one parameter $array, that is the input array and pops out the last element from it, reducing the size by one.
Return Value: This function returns the last element of the array. If the array is empty or the input parameter is not an array, then NULL is returned.
Note: This function resets the (reset()) the array pointer of the input array after use.
Input : $array = (1=>"ram", 2=>"krishna", 3=>"aakash"); Output : aakash Input : $array = (24, 48, 95, 100, 120); Output : 120
Below programs illustrate the array_pop() function in PHP:
Popped element is aakash After popping the last element, the array reduces to: Array (  => ram  => krishna )
Popped element is 120 After popping the last element, the array reduces to: Array (  => 24  => 48  => 95  => 10 )
Exception: An E_WARNING exception is thrown if a non-array is passed which is a runtime error or warning. This warning will not stop the execution of script.
- How to get the function name inside a function in PHP ?
- p5.js | mag() Function
- p5.js | nfp() Function
- PHP Ds\Map sum() Function
- p5.js | nf() Function
- PHP | Ds\Set contains() Function
- PHP | Ds\Map first() Function
- PHP | pi( ) Function
- p5.js | nfc() function
- D3.js | d3.set.add() Function
- D3.js | d3.map.set() Function
- PHP | pow( ) Function
- D3.js | d3.lab() Function
- D3.js | d3.hcl() Function
- CSS | url() Function
- PHP | Ds\Set add() Function
- PHP | Ds\Set last() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai