Ds \ Stack::__construct()函數是PHP中的內置函數,用於創建新的堆棧實例。
用法:
public Ds\Stack::__construct( $values )
參數:此函數接受單個參數$values,該參數保存可遍曆的對象或數組以使用初始值。
以下示例程序旨在說明PHP中的Ds \ Stack::__construct()函數:
程序1:
<?php
// Declare a new stack
$stack = new \Ds\Stack();
print_r($stack);
// Declare a new stack
$stack = new \Ds\Stack(['G', 'E', 'K', 'S']);
print_r($stack);
?>
輸出:
Ds\Stack Object
(
)
Ds\Stack Object
(
[0] => S
[1] => K
[2] => E
[3] => G
)
程序2:
<?php
// Declare a new stack
$stack = new \Ds\Stack([2, 3, 6, 7, 8]);
var_dump($stack);
// Declare a new stack
$stack = new \Ds\Stack([2, 3, 5, 8, 9, 10]);
var_dump($stack);
?>
輸出:
object(Ds\Stack)#1 (5) {
[0]=>
int(8)
[1]=>
int(7)
[2]=>
int(6)
[3]=>
int(3)
[4]=>
int(2)
}
object(Ds\Stack)#2 (6) {
[0]=>
int(10)
[1]=>
int(9)
[2]=>
int(8)
[3]=>
int(5)
[4]=>
int(3)
[5]=>
int(2)
}
參考: https://www.php.net/manual/en/ds-stack.construct.php
相關用法
- p5.js arc()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP abs()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- PHP exp()用法及代碼示例
- CSS hsl()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | Ds\Stack __construct() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
