PHP | SplDoublyLinkedList setIteratorMode() Function
Last Updated :
21 Nov, 2019
The SplDoublyLinkedList::setIteratorMode() function is an inbuilt function in PHP which is used to set the mode of iteration.
Syntax:
void SplDoublyLinkedList::setIteratorMode( int $mode )
Parameters: This function accepts single parameter $mode which holds two orthogonal sets of modes which are listed below:
The direction of the iteration are:
- SplDoublyLinkedList::IT_MODE_LIFO (Stack style)
- SplDoublyLinkedList::IT_MODE_FIFO (Queue style)
The behavior of the iterator are:
- SplDoublyLinkedList::IT_MODE_DELETE (Elements are deleted by the iterator)
- SplDoublyLinkedList::IT_MODE_KEEP (Elements are traversed by the iterator)
Return Value: This function does not return any value.
Below programs illustrate the SplDoublyLinkedList::setIteratorMode() function in PHP:
Program 1:
<?php
$list = new SplDoublyLinkedList();
$list ->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
$mode = $list ->getIteratorMode();
var_dump( $mode );
$list ->setIteratorMode(SplDoublyLinkedList::IT_MODE_DELETE);
$mode = $list ->getIteratorMode();
var_dump( $mode );
$list ->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
$mode = $list ->getIteratorMode();
var_dump( $mode );
?>
|
Output:
int(0)
int(1)
int(2)
Program 2:
<?php
$list = new 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);
?>
|
Output:
int(0)
int(2)
int(1)
int(0)
Reference: https://www.php.net/manual/en/spldoublylinkedlist.setiteratormode.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...