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.
Sorting XML and JSON with SplDoublyLinkedList - PHP Tutorial
From the course: Learning the Standard PHP Library
Sorting XML and JSON with SplDoublyLinkedList
A doubly-linked list can store not only simple values such as strings and numbers, it can also be used with complex values such as objects. This is doublylinked.php, which you can find in the Chapter 7 folder of the exercise files. It loads the data in courses.xml, a Simple XML, and then loops through it to display the author, title and duration of each course. If we load this page into a browser, each course is displayed in the same order as in the original .xml. Let's use a doubly-linked list to sort the courses according to the author's last name, using an algorithm called "insertion sort". This relies on SplDoublyLinkedList's add() method, so it requires PHP 5.5 or later. So let's get to the code. I want to use $courses as the name for the doubly-linked list. So we need to rename the variable that loads the data on Line 2. So we'll call that simply, $data. And on the next line, we'll create our doubly-linked list, which we'll call $courses. That's new SplDoublyLinkedList(); The…
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)
-