PHP的Ds \ Stack::clear()函數用於從堆棧中刪除所有元素並清除它。此函數隻是從堆棧中刪除所有元素,而不能完全刪除它。它隻是清空。
用法:
void public Ds\Stack::clear ( void )
參數:此函數不接受任何參數。
返回值:此函數不返回任何值。
以下示例程序旨在說明Ds \ Stack::clear()函數:
程序1:
<?php
// PHP program to illustarte the
// clear() function
// Create a Stack instance
$stack = new \Ds\Stack();
// Pushing elements to Stack
$stack->push("Welcome");
$stack->push("to");
$stack->push("GfG");
// Print the stack
print_r($stack);
// clear the stack
$stack->clear();
// Print the stack again
print_r($stack);
?>輸出:
Ds\Stack Object
(
[0] => GfG
[1] => to
[2] => Welcome
)
Ds\Stack Object
(
)
程序2::
<?php
// PHP program to illustarte the
// clear() 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
print_r($stack);
// clear the stack
$stack->clear();
// Print the stack again
print_r($stack);
?>輸出:
Ds\Stack Object
(
[0] => 5.5
[1] => 10
[2] => GfG
[3] => to
[4] => Welcome
)
Ds\Stack Object
(
)
參考:http://php.net/manual/en/ds-stack.clear.php
相關用法
- PHP Ds\Set clear()用法及代碼示例
- PHP DS\Map clear()用法及代碼示例
- PHP Ds\Deque clear()用法及代碼示例
- PHP Imagick clear()用法及代碼示例
- PHP Ds\Pair clear()用法及代碼示例
- PHP Gmagick clear()用法及代碼示例
- PHP Ds\PriorityQueue clear()用法及代碼示例
- PHP Ds\Queue clear()用法及代碼示例
- PHP Ds\Collection clear()用法及代碼示例
- PHP Ds\Vector clear()用法及代碼示例
- PHP ImagickDraw clear()用法及代碼示例
- PHP exp()用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP abs()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 PHP | Ds\Stack clear() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
