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.
Creating a recursive callback filter - PHP Tutorial
From the course: Learning the Standard PHP Library
Creating a recursive callback filter
- To use a callback function to filter a multidimensional structure you need to use the recursive callback filter iterator class. It's a bit of a mouthfull, but it does what it says. It's basically the same as callback filter iterator, but the callback function must also return true if the current element has children. This is recursive_callback.php, which you can find in the chapter three folder of the exercise files. It sets up a recursive directory iterator to traverse the common directory and it also sets the option to skip the dotfiles. Let's create a filter to select only files that are larger than six kilobytes. So files, and then we need a new recursive callback filter iterator, and the first argument of that is the iterator that we want to filter, which is called files, and the second argument is the callback function. We'll use an anonymous function as the callback. So function, and then we need to decide how many arguments to pass to this. It will take up to three…
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)
-
-
-
-
-