Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

8.8 Standard-Datenstrukturen nicht neu erfinden – Queues, Stacks und Co.

Problem

Sie benötigen in Ihrem Programm Datenstrukturen, die PHP nicht out-of-the-box bietet (z.B. Stack, Linked-List oder Queue). Sie könnten diese mithilfe von Arrays als eigene Klasse implementieren, sind sich aber nicht sicher, ob Sie dabei nicht unnötig das Rad neu erfinden.

Lösung

Seit PHP 5.3 bietet die Standard PHP Library (SPL) einige dieser Datenstrukturen an. Die Klasse SplStack implementiert eine LIFO-Datenstruktur (Last-In-First-Out) und somit eine Datenstruktur, die sich wie ein Stack (engl. für Stapel) verhält:

$stack = new SplStack(); $stack->push('a'); $stack->push('b'); $stack->push('c'); echo $stack->pop()."\n"; echo $stack->pop()."\n"; echo $stack->pop()."\n"; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book