本篇文章給大家介紹一下PHP使用“SplQueue::__construct()”函數(shù)的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。
PHP如何使用SplQueue::__construct()函數(shù)?示例
SplQueue::__construct()函數(shù)是PHP中的內(nèi)置函數(shù), 用于構建使用雙鏈表實現(xiàn)的隊列。
語法如下:
void SplQueue::__construct(void)
參數(shù):此函數(shù)不接受任何參數(shù)。
返回值:此函數(shù)不返回任何值。
下面的程序說明了SplQueue::__ construct()PHP中的函數(shù):
程序1:
<?php // Create a new empty queue $q = new SplQueue(); $q [] = 1; $q [] = 2; $q [] = 3; // Print the queue elements echo $q [0] . "n" ; echo $q [1] . "n" ; echo $q [2] . "n" ; ?>
輸出如下:
1 2 3
程式2:
<?php // Create some fixed size array $gfg = new SplQueue(); $gfg [] = 1; $gfg [] = 5; $gfg [] = 1; $gfg [] = 11; $gfg [] = 15; $gfg [] = 17; foreach ( $gfg as $elem ) { echo $elem . "n" ; } ?>
輸出如下:
1 5 1 11 15 17
推薦學習:php視頻教程