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.

Specifying a range of items with LimitIterator

Specifying a range of items with LimitIterator - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

Specifying a range of items with LimitIterator

- I've got open limit.php, which loads courses.xml in the common data directory as simple XML and then displays the title, author and duration of each course. You can find a copy of this file in the chapter three folder of the exercise files. If we load this page into a browser, the details of all the courses are displayed. But let's say we want only the first 10. We can do that with limit iterator. So let's get back to the code. And the first thing that we need to do is to convert the simple XML element object into an iterator by adding the name of the simple XML iterator class as the second argument to simple XML load file. So let's add that second argument in there. It needs to be a string, SimpleXMLIterator. And this is case insensitive. Now that we've converted it into an iterator, we can chain it with the limit iterator. So let's add a new line on line three. We'll keep the same name, courses, and then it's new LimitInterator. The first argument is the iterator we want to limit.…

Contents