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 // 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)
Program 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)
Reference: https://www.php.net/manual/en/spldoublylinkedlist.setiteratormode.php