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

Keeping priority items in chronological order - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

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…

Contents