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.
Generating an ASCII graphic tree with RecursiveTreeIterator - PHP Tutorial
From the course: Learning the Standard PHP Library
Generating an ASCII graphic tree with RecursiveTreeIterator
- The RecursiveTreeIterator class simply iterates over another recursive iterator to generate an ASCII graphic tree of the elements it contains. This is recursivetree.php, which you can find in the chapter six folder of the exercise files. It contains an instance of recursive directory iterator that traverses the common directory, and its sub-directories. To create a graphic tree, just chain RecursiveTreeIterator and then create a loop to display the values. There's no need to use the RecursiveIterator iterator because RecursiveTreeIterator does is all for you. So let's create that here. Files new RecursiveTreeIterator, and we pass it a RecursiveIterator which is called files, and then we just loop over it, foreach files as file, and then inside that loop we echo file and have a line break. Our base iterator is RecursiveDirectoryIterator, so inside this loop, file will be the relative path to each file. So we just save that and then load it into a browser, and that creates the graphic…
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)
Creating a repeat sequence with InfiniteIterator3m 35s
-
(Locked)
Treating the final element differently with CachingIterator4m 14s
-
(Locked)
Using RecursiveCachingIterator with multidimensional structures2m 59s
-
(Locked)
Generating an ASCII graphic tree with RecursiveTreeIterator4m 28s
-
(Locked)
NoRewindIterator and EmptyIterator2m 26s
-
(Locked)
-
-