PHP中的Ds \ Queue::pop()函数用于删除并返回队列顶部的值。换句话说,它返回出现在队列前面的值,并将其从队列中删除。
用法:
mixed public Ds\PriorityQueue::pop ( void )
参数:该函数不接受任何参数。
返回值:此函数返回Queue顶部的现值。函数的返回类型是混合的,并且取决于存储在队列中的值的类型。
异常:如果Queue为空,则此函数引发UnderflowException。
以下示例程序旨在说明PHP中的Ds \ Queue::pop()函数:
程序1:
<?php
// Declare new Queue
$q = new \Ds\Queue();
// Add elements to the Queue
$q->push("One");
$q->push("Two");
$q->push("Three");
echo "Initial Queue is:\n";
print_r($q);
// Pop an element
echo "\nPopped element is:";
print_r($q->pop());
echo "\n\nFinal Queue is:\n";
print_r($q);
?>
输出:
Initial Queue is:
Ds\Queue Object
(
[0] => One
[1] => Two
[2] => Three
)
Popped element is:One
Final Queue is:
Ds\Queue Object
(
[0] => Two
[1] => Three
)
程序2:
<?php
// Declare new Queue
$q = new \Ds\Queue();
// Add elements to the Queue
$q->push("Geeks");
$q->push("for");
$q->push("Geeks");
echo "Initial Queue is:\n";
print_r($q);
// Pop an element
echo "\nPopped element is:";
print_r($q->pop());
echo "\n\nFinal Queue is:\n";
print_r($q);
?>
输出:
Initial Queue is:
Ds\Queue Object
(
[0] => Geeks
[1] => for
[2] => Geeks
)
Popped element is:Geeks
Final Queue is:
Ds\Queue Object
(
[0] => for
[1] => Geeks
)
参考: http://php.net/manual/en/ds-queue.pop.php
相关用法
- PHP ord()用法及代码示例
- PHP each()用法及代码示例
- PHP dir()用法及代码示例
- PHP exp()用法及代码示例
- PHP Ds\Map map()用法及代码示例
- PHP Ds\Map last()用法及代码示例
- PHP tan( )用法及代码示例
- PHP pos()用法及代码示例
- PHP key()用法及代码示例
- PHP min( )用法及代码示例
- PHP each()用法及代码示例
- PHP end()用法及代码示例
- PHP cos( )用法及代码示例
- PHP abs()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 PHP Ds\Queue pop() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
