Ds \ Deque::pop()函数是PHP中的内置函数,用于从Deque中删除最后一个元素(如果Deque不为空)并返回它。如果Deque为空,则抛出异常。
用法:
public Ds\Deque::pop( void ):mixed
参数:该函数不接受任何参数。
返回值:此函数返回从双端队列中删除的最后一个元素。
以下示例程序旨在说明PHP中的Ds \ Deque::pop()函数:
程序1:
<?php
// Declare a deque
$deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]);
echo("Elements of Deque\n");
// Display the Deque elements
print_r($deck);
// last element in the deque
echo("\nLast element of deque:");
// Use pop() function to removing last
// element from Deque and Display it
print_r($deck->pop());
echo("\nElements of Deque\n");
// Display the Deque elements
print_r($deck);
?>
输出:
Elements of Deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 ) Last element of deque:60 Elements of Deque Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 )
程序2:
<?php
// Declare a deque
$deck = new \Ds\Deque(["geeks", "for", "geeks", "practice"]);
echo("Elements of Deque\n");
// Display the Deque elements
print_r($deck);
// last element in the deque
echo("\nLast element of deque:");
// Use pop() function to removing last
// element from Deque and Display it
print_r($deck->pop());
echo("\nElements of Deque\n");
// Display the Deque elements
print_r($deck);
?>
输出:
Elements of Deque Ds\Deque Object ( [0] => geeks [1] => for [2] => geeks [3] => practice ) Last element of deque:practice Elements of Deque Ds\Deque Object ( [0] => geeks [1] => for [2] => geeks )
参考: http://php.net/manual/en/ds-deque.pop.php
相关用法
- d3.js d3.lab()用法及代码示例
- PHP exp()用法及代码示例
- PHP Ds\Map put()用法及代码示例
- d3.js d3.hcl()用法及代码示例
- PHP sin( )用法及代码示例
- PHP abs()用法及代码示例
- PHP cos( )用法及代码示例
- PHP tan( )用法及代码示例
- d3.js d3.map.set()用法及代码示例
- PHP next()用法及代码示例
- PHP Ds\Map get()用法及代码示例
- d3.js d3.sum()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Deque pop() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。