PHP array_pop() function has the following syntax.
mixed array_pop ( array &arr )
The array_pop()
function returns the value
from the end of the array and removes it from the array.
array_pop() is the counterpart to array_shift();
array_push()
and array_pop()
are
useful for creating a stack which is a last-in, first-out
(LIFO) structure.
We can add new values onto the "top" of the
stack with array_push()
, then retrieve the most recently
added value with array_pop()
.
Popup value from an Array
<?PHP
$names = array("Java", "PHP", "Python", "HTML","java2s.com", "CSS");
$firstname = array_pop($names);
print($firstname);
print_r($names);
?>
The code above generates the following result.
Popup element from associate array
<?PHP
$myBook = array( "title" => "Learn PHP from java2s.com",
"author" => "java2s.com",
"pubYear" => 2000 );
echo array_pop( $myBook ) . "\n";
print_r( $myBook );
?>
The code above generates the following result.