From the course: Learning the Standard PHP Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Keeping priority items in chronological order - PHP Tutorial
From the course: Learning the Standard PHP Library
Keeping priority items in chronological order
- We've created a priority queue that sorts the php error log according to the error level, with fatal errors first, followed by warnings, and then less important errors. The SplPriorityQueue class is implemented using a max heap, so items of the same priority are not listed in any particular order. If you want to preserve the original order within each priority group, you need to extend the SplpPriorityQueue class. This solution incidentally was published anonymously in the user notes of the PHP online documentation. So whoever came up with it deserves a vote of thanks. This is priority_order.php which you can find in the chapter seven folder of the exercise files. It contains exactly the same code as at the end of the previous video. So what we need to do is to extend SplPriorityQueue. Let's do that at the top of the file. So type in a couple of lines on line two and then we'll call the class OrderedPriority and it extends SplPriorityQueue. To preserve the original order, we need to…
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
-
-
-
-
-
-
-
-
-
(Locked)
Doubly linked lists, stacks, and queues3m 10s
-
(Locked)
Sorting XML and JSON with SplDoublyLinkedList8m 26s
-
(Locked)
Using SplStack and SplQueue6m 25s
-
(Locked)
Understanding heaps2m 55s
-
(Locked)
SplMinHeap and SplMaxHeap5m 3s
-
(Locked)
Sorting XML and JSON with SplHeap7m 9s
-
(Locked)
Finding important information with SplPriorityQueue5m 32s
-
(Locked)
Keeping priority items in chronological order4m 23s
-
(Locked)
Speeding up array access with SplFixedArray6m 48s
-
(Locked)
-