PHP | SplDoublyLinkedList __construct() Function

The SplDoublyLinkedList::__construct() function is an inbuilt function in PHP which is used to create a new empty doubly linked list.

Syntax:

public SplDoublyLinkedList::__construct( void )

Parameters: This function does not accept any parameter.

Return Value: This function does not return any value.

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



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare an empty SplDoublyLinkedList 
$list = new SplDoublyLinkedList();
  
// Push the element into SplDoublyLinkedList
$list->push(10);
$list->push(20);
$list->push(30);
  
// Display the SplDoublyLinkedList
var_dump($list);
?>

chevron_right


Output:

object(SplDoublyLinkedList)#1 (2) {
  ["flags":"SplDoublyLinkedList":private]=>
  int(0)
  ["dllist":"SplDoublyLinkedList":private]=>
  array(3) {
    [0]=>
    int(10)
    [1]=>
    int(20)
    [2]=>
    int(30)
  }
}

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->add(0, "Welcome"); 
$list->add(1, "to"); 
$list->add(2, "GeeksforGeeks"); 
$list->add(3, "A"); 
$list->add(4, "Computer");
$list->add(5, "Science");
$list->add(6, "Portal");
  
// Display the SplDoublyLinkedList
var_dump($list);
?>

chevron_right


Output:

object(SplDoublyLinkedList)#1 (2) {
  ["flags":"SplDoublyLinkedList":private]=>
  int(0)
  ["dllist":"SplDoublyLinkedList":private]=>
  array(7) {
    [0]=>
    string(7) "Welcome"
    [1]=>
    string(2) "to"
    [2]=>
    string(13) "GeeksforGeeks"
    [3]=>
    string(1) "A"
    [4]=>
    string(8) "Computer"
    [5]=>
    string(7) "Science"
    [6]=>
    string(6) "Portal"
  }
}

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