From the course: Learning the Standard PHP Library
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Using SplStack and SplQueue - PHP Tutorial
From the course: Learning the Standard PHP Library
Using SplStack and SplQueue
- SplStack and SplQueue are specialized versions of WLinkLists. SplStack works on the basis of last in first out while SplQueue processes values on a first in first out basis. This is stack_queue.php which you can find in the chapter seven folder of the exercise files. The code on lines two to seven creates an instance of SplStack and populates it with the letters A to E. It uses a mixture of bracket notation and the push method. With bracket notation, you assign the value in the same way as you would with an ordinary array. With push method, you pass the value as an argument. It doesn't matter which you choose. Lines nine to 14, create an instance of SplQueue which is also populated with the letters A to E. On lines 10 and 11, the enqueue method is used and on line 12, the push method and lines 13 and 14, use bracket notation. They all do exactly the same thing, they add items to the list. Then we've got two for each loops that display the contents of the stack and queue. Let's load…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
Doubly linked lists, stacks, and queues3m 10s
-
Sorting XML and JSON with SplDoublyLinkedList8m 26s
-
Using SplStack and SplQueue6m 25s
-
Understanding heaps2m 55s
-
SplMinHeap and SplMaxHeap5m 3s
-
Sorting XML and JSON with SplHeap7m 9s
-
Finding important information with SplPriorityQueue5m 32s
-
Keeping priority items in chronological order4m 23s
-
Speeding up array access with SplFixedArray6m 48s
-
-