(PHP 4, PHP 5)
Definition and Usage. The pop method removes the last element of an array, and returns that element. Note: This method changes the length of an array. Definition and Usage This function pops and returns the last value of the array, shortening the array by one element.
array_pop — Pop the element off the end of array
Description
array_pop() pops and returns the last value of the array
, shortening the array
by one element. If array
is empty (or is not an array), NULL
will be returned. Will additionally produce a Warning when called on a non-array.
Note: This function willreset() the array pointer of the input array afteruse.
Return Values
Returns the last value of array
. If array
is empty (or is not an array), NULL
will be returned.
Examples
Example #1 array_pop() example Vs2008 sp1.
$stack = array('orange', 'banana', 'apple', 'raspberry');
$fruit = array_pop($stack);
print_r($stack);
?>
and raspberry will be assigned to $fruit.
See Also
- array_push() - Push one or more elements onto the end of array
- array_shift() - Shift an element off the beginning of array
- array_unshift() - Prepend one or more elements to the beginning of an array
Execute array_pop ( &$array );
Example
Delete the last element of an array:
array_pop($a);
print_r($a);
?>
Note: This function willreset() the array pointer of the input array afteruse.
Return Values
Returns the last value of array
. If array
is empty (or is not an array), NULL
will be returned.
Examples
Example #1 array_pop() example Vs2008 sp1.
$stack = array('orange', 'banana', 'apple', 'raspberry');
$fruit = array_pop($stack);
print_r($stack);
?>
and raspberry will be assigned to $fruit.
See Also
- array_push() - Push one or more elements onto the end of array
- array_shift() - Shift an element off the beginning of array
- array_unshift() - Prepend one or more elements to the beginning of an array
Execute array_pop ( &$array );
Example
Delete the last element of an array:
array_pop($a);
print_r($a);
?>
Run example »
Definition and Usage
The array_pop() function deletes the last element of an array.
Syntax
Parameter | Description |
---|---|
array | Required. Specifies an array |
Php Remove Array Element
Technical Details
Return Value: | Returns the last value of array. If array is empty, or is not an array, NULL will be returned. |
---|---|
PHP Version: | 4+ |
PHP Array Reference
Top 10 Tutorials
HTML TutorialCSS Tutorial
JavaScript Tutorial
XML Tutorial
SQL Tutorial
PHP Tutorial
ASP.NET Tutorial
jQuery Tutorial
Angular Tutorial
Bootstrap Tutorial
Top 10 References
HTML ReferenceCSS Reference
JavaScript Reference
Browser Statistics
HTML DOM
XML DOM
PHP Reference
jQuery Reference
HTML Colors
HTML Character Sets
Array Pop Python
Top 10 Examples
HTML ExamplesCSS Examples
JavaScript Examples
HTML DOM Examples
PHP Examples
jQuery Examples
XML Examples
XML DOM Examples
ASP Examples
SVG Examples
Web Certificates
HTML CertificateHTML5 Certificate
CSS Certificate
JavaScript Certificate
jQuery Certificate
PHP Certificate
XML Certificate
Thank You For Helping Us!
Your message has been sent to W3Schools.