the SplStack is simply a SplDoublyLinkedList with an iteration mode IT_MODE_LIFO and IT_MODE_KEEP
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
A classe SplStack fornece as principais funcionalidades de uma pilha implementada usando uma lista duplamente encadeada
definindo o modo do iterador como SplDoublyLinkedList::IT_MODE_LIFO
.
Exemplo #1 Exemplo de SplStack
<?php
$q = new SplStack();
$q[] = 1;
$q[] = 2;
$q[] = 3;
foreach ($q as $elem) {
echo $elem."\n";
}
?>
O exemplo acima produzirá:
3 2 1
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