array_pop

array_pop 函數 官方說明:

mixed array_pop ( array &$array )

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 will reset() the array pointer after use.

Parameters

array:The array to get the value from.

Return Values:

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

 

測試代碼如下:

/**
  * Tests array_pop()
  */
 public function testArray_pop() {
  //  array_pop(/* parameters */);
  $stack = array ("orange", "banana", "apple", "raspberry" );
  $fruit = array_pop ( $stack );
  print_r ( $stack );
  $this->assertArrayNotHasKey("raspberry",$stack,"$stack is still has the key \'raspberry\'");
  $stack_null =null;
  array_pop($stack_null);
  $array_empty = array();
  $this->assertNull(array_pop($array_empty),"function array_pop($array_empty) return not null");
  print_r($array_empty);
 }

測試結果如下:

Content-type: text/html
Array
(
    [0] => orange
    [1] => banana
    [2] => apple
)

Warning: array_pop(): The argument should be an array in D:\php\phpworkspace\php\array_popTest.php on line 48
Array
(
)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值