PHP | SplDoublyLinkedList getIteratorMode() Function

The SplDoublyLinkedList::getIteratorMode() function is an inbuilt function in PHP which is used to return the mode of iteration.

Syntax:

int SplDoublyLinkedList::getIteratorMode( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the different modes and flags that affect the iteration.

Below programs illustrate the SplDoublyLinkedList::getIteratorMode() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


Output:

int(0)
int(1)
int(2)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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); 
  
?>

chevron_right


Output:

int(0)
int(2)
int(1)
int(0)

Reference: https://www.php.net/manual/en/spldoublylinkedlist.getiteratormode.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.