EZ

Eduzan

Learning Hub

Eduzan
Eduzan / PHP

PHP SPL Data structures

Computer Science / PHP tutorial chapter - Published 2025-12-16 - PHP

add()
Description: Add a new value at the given index in the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->add(0, "A");
$list->add(1, "B");

print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)

bottom()
Description: Peek the value of the node from the beginning of the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->bottom();
// Output: A

count()
Description: Count the number of elements present in a doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->count();
// Output: 2

push()
Description: Push an element at the end of the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)

unshift()
Description: Add an element at the beginning of the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("B");
$list->unshift("A");

print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)

top()
Description: Return the value of the last (top) node in a doubly-linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->top();
// Output: B

pop()
Description: Pop the node from the end of the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->pop();
// Output: B

isEmpty()
Description: Check whether the doubly linked list is empty.
Example:

$list = new SplDoublyLinkedList();

echo $list->isEmpty();
// Output: 1 (true)

rewind()
Description: Rewind the iterator back to the start or beginning of the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

$list->rewind();
echo $list->current();
// Output: A

shift()
Description: Remove the first element from the doubly linked list and return it.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->shift();
// Output: A

add()
Description: Add a new value at the given index in the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->add(0, "A");
$list->add(1, "B");

print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)

bottom()
Description: Peek the value of the node from the beginning of the doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->bottom();
// Output: A

count()
Description: Count the number of elements present in a doubly linked list.
Example:

$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");

echo $list->count();
// Output: 2
End of lesson.