From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Build nested unordered lists automatically

Build nested unordered lists automatically

From the course: PHP Tips, Tricks, and Techniques

Build nested unordered lists automatically

- [Instructor] Hi, I'm David Powers, and welcome to this week's edition of PHP Tips and Tricks designed to help you become a smarter more productive PHP developer. Building an HTML unordered list from an indexed array is pretty basic. One way to do it is with a foreach loop like this. And there's the result. All fairly straightforward. But what about dealing with a multidimensional associative array? I've got one in this other file. Nested lists present a much bigger challenge, and that's what we'll tackle this week. If you want to follow along, grab the download files that accompany this video. To deal with a multidimensional array, we're going to need a little bit of help from the standard PHP library, or SPL. A useful set of built-in PHP classes. I've already started building the code in this other file, ListBuilder.php. It defines a custom class called ListBuilder that extends the SPL's RecursiveIteratorIterator that can loop recursively over a structure such as a multidimensional…

Contents