php8.5
Home/ Manual/ reference / spl/ The SplStack class

The SplStack class

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.

Intro

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 { }

Examples

SplStack example

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

The above example will output:

output
3
2
1

Source: reference/spl/splstack.xml · from the official PHP manual (php/doc-en)