The SplStack class

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Introduction

The SplStack class provides the main functionalities of a stack implemented using a doubly linked list by setting the iterator mode to SplDoublyLinkedList::IT_MODE_LIFO.

Class synopsis

class SplStack extends SplDoublyLinkedList {
/* Inherited constants */
/* Inherited methods */
public SplDoublyLinkedList::add(int $index, mixed $value): void
public SplDoublyLinkedList::offsetExists(int $index): bool
public SplDoublyLinkedList::offsetSet(?int $index, mixed $value): void
public SplDoublyLinkedList::offsetUnset(int $index): void
public SplDoublyLinkedList::push(mixed $value): void
public SplDoublyLinkedList::unserialize(string $data): void
public SplDoublyLinkedList::unshift(mixed $value): void
}

Examples

Example #1 SplStack example

<?php
$q
= new SplStack();
$q[] = 1;
$q[] = 2;
$q[] = 3;
foreach (
$q as $elem) {
echo
$elem."\n";
}
?>

The above example will output:

3
2
1