ABSTRACT

This chapter covers two topics: the Standard PHP Library (SPL) and Iterator interface. The Standard PHP Library is a collection of interfaces and classes that provides efficient data access through sophisticated types of looping for aggregate structures such as arrays, database result sets, XML trees, and directory listings. SPL is based on the Iterator interface, which is an effective mechanism for traversing the elements of an aggregate structure. The chapter examines how to use selected SPL classes to efficiently iterate over an aggregate structure and how to use the Iterator interface to better understand the looping process and gain more control over aggregate structure iteration. The Iterator interface requires the programmer to implement five methods, such as current, key, next, rewind, and valid. Although SPL functionality is based on the Iterator interface, the complexities involved are transparent to the programmer. This is because Iterator interface logic is internal to SPL classes and interfaces.