Open In App

PHP | SplDoublyLinkedList __construct() Function

Last Updated : 07 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
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: php
<?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);
?>
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: php
<?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);
?>
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"
  }
}

Next Article

Similar Reads