数组 函数
PHP 手册

array_pop

(PHP 4, PHP 5)

array_pop将数组最后一个单元弹出(出栈)

说明

mixed array_pop ( array &$array )

array_pop() 弹出并返回 array 数组的最后一个单元,并将数组 array 的长度减一。如果 array 为空(或者不是数组)将返回 NULL。 Will additionally produce a Warning when called on a non-array.

Note: 使用此函数后会重置( reset()array 指针。

参数

array

The array to get the value from.

返回值

Returns the last value of array. If array is empty (or is not an array), NULL will be returned.

范例

Example #1 array_pop() 例子

<?php
$stack 
= array("orange""banana""apple""raspberry");
$fruit array_pop($stack);
print_r($stack);
?>

经过此操作后,$stack 将只有 3 个单元:

Array
(
    [0] => orange
    [1] => banana
    [2] => apple
)

并且 rasberry 将被赋给 $fruit

参见


数组 函数
PHP 手册