<?php
# Think of the stack as an array reversed, where the last element has index zero
$stack = new SplStack();
$stack->push('a');
$stack->push('b');
$stack->push('c');
$stack->offsetSet(0, 'C'); # the last element has index zero
$stack->rewind();
while( $stack->valid() )
{
echo $stack->current(), PHP_EOL;
$stack->next();
}
/*
OUTPUT
****************************
C
b
a
*/
?>
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

Sandro Alves Peres ¶
4 months ago