Open In App

PHP | SplDoublyLinkedList getIteratorMode() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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:




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


Output:

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


Output:

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

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



Last Updated : 21 Nov, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads