PHP 8.6.0 Beta 1 is available for testing

La clase SplStack

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

Introducción

La clase SplStack proporciona la funcionalidad principal de una pila implementada mediante una lista doblemente enlazada estableciendo el modo iterador a SplDoublyLinkedList::IT_MODE_LIFO .

Sinopsis de la clase

class SplStack extends SplDoublyLinkedList {
/* Constantes heredadas */
/* Métodos heredados */
public function SplDoublyLinkedList::add (int $index, mixed $value): void
public function SplDoublyLinkedList::bottom (): mixed
public function SplDoublyLinkedList::count (): int
public function SplDoublyLinkedList::current (): mixed
public function SplDoublyLinkedList::isEmpty (): bool
public function SplDoublyLinkedList::key (): int
public function SplDoublyLinkedList::next (): void
public function SplDoublyLinkedList::offsetExists (int $index): bool
public function SplDoublyLinkedList::offsetGet (int $index): mixed
public function SplDoublyLinkedList::offsetSet (? int $index, mixed $value): void
public function SplDoublyLinkedList::offsetUnset (int $index): void
public function SplDoublyLinkedList::pop (): mixed
public function SplDoublyLinkedList::prev (): void
public function SplDoublyLinkedList::push (mixed $value): void
public function SplDoublyLinkedList::rewind (): void
public function SplDoublyLinkedList::setIteratorMode (int $mode): int
public function SplDoublyLinkedList::shift (): mixed
public function SplDoublyLinkedList::top (): mixed
public function SplDoublyLinkedList::unserialize (string $data): void
public function SplDoublyLinkedList::unshift (mixed $value): void
public function SplDoublyLinkedList::valid (): bool
}

Ejemplos

Ejemplo #1 Ejemplo de SplStack

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

El ejemplo anterior mostrará:

3
2
1

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 2 notes

up
42
lsroudi at gmail dot com
12 years ago
the SplStack is simply a SplDoublyLinkedList with an iteration mode IT_MODE_LIFO and IT_MODE_KEEP
up
8
lincoln dot du dot j at gmail dot com
9 years ago
<?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
+add a note

AltStyle によって変換されたページ (->オリジナル) /