SplDoublyLinkedList::setIteratorMode()函數是PHP中的一個內置函數,用於設置迭代模式。
用法:
void SplDoublyLinkedList::setIteratorMode( int $mode )
參數:該函數接受單個參數$mode,該參數包含兩個正交的模式集,如下所示:
迭代的方向是:
- SplDoublyLinkedList::IT_MODE_LIFO(堆棧樣式)
- SplDoublyLinkedList::IT_MODE_FIFO(隊列樣式)
迭代器的行為是:
- SplDoublyLinkedList::IT_MODE_DELETE(元素由迭代器刪除)
- SplDoublyLinkedList::IT_MODE_KEEP(元素被迭代器遍曆)
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的SplDoublyLinkedList::setIteratorMode()函數:
程序1:
<?php
// Declare an empty SplDoublyLinkedList
$list = new SplDoublyLinkedList();
// Add the element into SplDoublyLinkedList
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
// Use getIteratorMode() function
$mode = $list->getIteratorMode();
var_dump($mode);
// Add the element into SplDoublyLinkedList
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_DELETE);
// Use getIteratorMode() function
$mode = $list->getIteratorMode();
var_dump($mode);
// Add the element into SplDoublyLinkedList
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
// Use getIteratorMode() function
$mode = $list->getIteratorMode();
var_dump($mode);
?>
輸出:
int(0) int(1) int(2)
程序2:
<?php
// Declare an empty SplDoublyLinkedList
$list = new SplDoublyLinkedList();
// Add the element into SplDoublyLinkedList
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO
| SplDoublyLinkedList::IT_MODE_DELETE
| SplDoublyLinkedList::IT_MODE_LIFO);
$mode = $list->getIteratorMode();
var_dump($mode & SplDoublyLinkedList::IT_MODE_FIFO);
var_dump($mode & SplDoublyLinkedList::IT_MODE_LIFO);
var_dump($mode & SplDoublyLinkedList::IT_MODE_DELETE);
var_dump($mode & SplDoublyLinkedList::IT_MODE_KEEP);
?>
輸出:
int(0) int(2) int(1) int(0)
參考: https://www.php.net/manual/en/spldoublylinkedlist.setiteratormode.php
相關用法
- PHP SplDoublyLinkedList add()用法及代碼示例
- PHP SplDoublyLinkedList pop()用法及代碼示例
- PHP SplDoublyLinkedList next()用法及代碼示例
- PHP SplDoublyLinkedList key()用法及代碼示例
- PHP SplDoublyLinkedList top()用法及代碼示例
- PHP SplDoublyLinkedList offsetGet()用法及代碼示例
- PHP SplDoublyLinkedList offsetExists()用法及代碼示例
- PHP SplDoublyLinkedList current()用法及代碼示例
- PHP SplDoublyLinkedList offsetSet()用法及代碼示例
- PHP SplDoublyLinkedList serialize()用法及代碼示例
- PHP SplDoublyLinkedList shift()用法及代碼示例
- PHP SplDoublyLinkedList getIteratorMode()用法及代碼示例
- PHP SplDoublyLinkedList unshift()用法及代碼示例
- PHP SplDoublyLinkedList __construct()用法及代碼示例
- PHP SplDoublyLinkedList rewind()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | SplDoublyLinkedList setIteratorMode() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。