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

Creating a recursive callback filter - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

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…

Contents