The SplStack class
(PHP 5 >= 5.3.0)
Introduction
The SplStack class provides the main functionalities of a stack implemented using a doubly linked list.
Class synopsis
Table of Contents
- SplStack::__construct — Constructs a new stack implemented using a doubly linked list
- SplStack::setIteratorMode — Sets the mode of iteration
Коментарии
the SplStack is simply a SplDoublyLinkedList with an iteration mode IT_MODE_LIFO and IT_MODE_KEEP
<?php
//SplStack Mode is LIFO (Last In First Out)
$q = new SplStack();
$q[] = 1;
$q[] = 2;
$q[] = 3;
$q->push(4);
$q->add(4,5);
$q->rewind();
while($q->valid()){
echo $q->current(),"\n";
$q->next();
}
?>
Output
5
4
3
2
1