PHP的Ds \ Stack::pop()函數用於刪除Stack實例頂部的元素。刪除堆棧後,此函數還返回堆棧的頂部元素。
用法:
mixed public Ds\Stack::pop ( void )
參數:該函數不接受任何參數。
返回值混合混合的此函數返回出現在堆棧頂部的元素,並將其從堆棧中刪除。
以下示例程序旨在說明PHP中的Ds \ Stack::pop()函數:
程序1:
<?php
// PHP program to illustarte the
// pop() function
// Create a Stack instance
$stack = new \Ds\Stack();
// Pushing elements to Stack
$stack->push("Welcome");
$stack->push("to");
$stack->push("GfG");
// Print the initial Stack
print_r($stack);
// Print the top element and remove it
print_r($stack->pop());
// Print the Stack again
print_r($stack);
?>輸出:
Ds\Stack Object
(
[0] => GfG
[1] => to
[2] => Welcome
)
GfG
Ds\Stack Object
(
[0] => to
[1] => Welcome
)
程序2:
<?php
// PHP program to illustarte the
// pop() function
// Create a Stack instance
$stack = new \Ds\Stack();
// Pushing Mixed value elements to Stack
$stack->push("Welcome");
$stack->push("to");
$stack->push("GfG");
$stack->push(10);
$stack->push(5.5);
// Print the Stack initially
print_r($stack);
// Print the top element and remove it
print_r($stack->pop());
// Print the stack again
print_r($stack);
?>輸出:
Ds\Stack Object
(
[0] => 5.5
[1] => 10
[2] => GfG
[3] => to
[4] => Welcome
)
5.5
Ds\Stack Object
(
[0] => 10
[1] => GfG
[2] => to
[3] => Welcome
)
參考:http://php.net/manual/en/ds-stack.pop.php
相關用法
- PHP pos()用法及代碼示例
- PHP key()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP end()用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP each()用法及代碼示例
- PHP pi( )用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP pow( )用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP min( )用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 PHP | Ds\Stack pop() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
