Blog de programación, errores, soluciones

Chose Language:
comments
Author: Admin/Publisher |finished | checked

PHP array_pop function

The PHP function array_pop removes the last element from an array and returns the removed element.

Resets the pointer of the given array; if you are using while to iterate through the array, this is something to keep in mind.
Description / Descripción
array_pop(array &$array): mixed
Sintaxis / Sintax
$value_poped = array_pop($array);

Before proceeding, note in the description that the array is passed by reference, &$array, and therefore, the original array will be changed.

Parameters

&$array – The array from which the last element will be removed, passing the value of the removed element as the return.

Returns

mixed – Returns the value of the removed element from the array.

null – in case the array is empty.

PHP array_pop example

We will only do an example of array_pop since it is a function that performs a very specific action

array_pop
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_pop($stack);
echo "valor eliminado: $fruit\n";
print_r($stack);
Category: en-php
Something wrong? If you found an error or mistake in the content you can contact me on Twitter | @luisg2249_luis.
Last 4 post in same category

Comments