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.
Using ParentIterator to find elements that have children - PHP Tutorial
From the course: Learning the Standard PHP Library
Using ParentIterator to find elements that have children
- ParentIterator is a specialize filter that selects on elements that have children. It can be useful for building menus or lists of top-level categories. This is parent.php, which you can find in the Chapter 3 folder of the exercise files. It simply contains an instance of recursive directory Iterator that starts at the current directory. So it will traverse the whole file system in the site and then it loops through it. So let's chain this with ParentIterator to filter out elements that don't have children. In other words, we're going to select only the directories. So, add a new line on line 3 and then its new ParentIterator and we pass it our Iterator. And then we need to chain that with RecursiveIterator Iterator. Now, there is actually a problem with this code, but I want to save the page first and load it into a browser to see what happens because it's such an easy mistake to make. So let's load that. The page is completely blank, but we've got no error messages. So let's go…
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)
Filtering a directory with GlobIterator5m 14s
-
(Locked)
Using regular expressions to filter directories with RegexIterator3m 49s
-
(Locked)
Extracting data from XML with RegexIterator and SimpleXML6m 25s
-
(Locked)
Specifying a range of items with LimitIterator4m 21s
-
(Locked)
Creating a custom filter with CallbackFilterIterator5m 6s
-
(Locked)
Creating a recursive callback filter5m 42s
-
(Locked)
Extending FilterIterator to create a reusable filter5m 10s
-
(Locked)
Creating a custom filter with RecursiveFilterIterator4m 48s
-
(Locked)
Overriding the RecursiveFilterIterator constructor5m 16s
-
(Locked)
Using ParentIterator to find elements that have children3m 59s
-
(Locked)
-
-
-
-
-