函式名:SplDoublyLinkedList::current()
適用版本:PHP 5 >= 5.3.0, PHP 7
函式描述:SplDoublyLinkedList::current() 方法用於獲取當前節點的值。
語法:public mixed SplDoublyLinkedList::current ( void )
引數:無
返回值:當前節點的值,如果當前節點不存在則返回 false。
示例:
$list = new SplDoublyLinkedList();
$list->push('Apple');
$list->push('Banana');
$list->push('Orange');
$list->rewind(); // 將指標指向第一個節點
echo $list->current(); // 輸出 "Apple"
$list->next(); // 將指標移動到下一個節點
echo $list->current(); // 輸出 "Banana"
$list->next();
echo $list->current(); // 輸出 "Orange"
在上面的示例中,我們建立了一個 SplDoublyLinkedList 物件,並向其新增了三個元素。然後我們使用 rewind() 方法將指標重置到第一個節點,並使用 current() 方法獲取當前節點的值。接著我們使用 next() 方法將指標移動到下一個節點,並再次使用 current() 方法獲取當前節點的值。最後一次使用 current() 方法獲取的值是最後一個節點的值。