Stefan "frostymarvelous" Froelich is a hobby programmer who loves to work with scripting languages. He's always up for a challenge and the opportunity to learn something new. At times he freelances, but mostly helps out in forums and various Q&A sites. His aim is to contribute to the community that has given so much to him over the years. Stefan dreams of a world where knowledge is freely shared.
Implementing the required interfaces to create an iterable object can be a hassle because of the amount of boilerplate code that is required. But with the release of PHP 5.5, we finally have generators! Take a look at how generators provide an easy way to implement simple iterators without the overhead or complexity of the Iterator interface.
Recursion is such that many experienced programmers can go years without using it and many others may never hear of it, which is a shame because it is a truly powerful concept. This article takes a broad look at recursion and how it compares to iteration, and then shows you how to write recursive functions, when to write them, and why you would want to.
There may be times when the provided iterators are insufficient for your needs and you’ll want to roll your own custom iterator. Luckily, SPL provides interfaces that will allow you to do just that. You’ll see how in this, the final part of a two-part series on using SPL iterators.
In part 1 of this two-part series discussing SPL Iterators you’ll see how you can take advantage of some of the built-in classes from the Standard PHP Library (SPL) making your code more efficient and readable.