19
1 2
3 $bookCollection = new BookCollection(
4 array(
5 new Book("50 shades of gray"),
6 new Book("The Hobbit"),
7 new Book("It"),
8 array('Discworld' =>
9 new Book("The colour of magic"),
10 new Book("A light fantastic"),
11 ),
12 array('Harry Potter' =>
13 new Book("Harry Potter and the deadly hallows"),
14 /* ... */
15 ),
16 /* ... */
17 ));
18
19 foreach ($bookCollection as $book) {
20 // Do something with all single books
21 }
22
23 foreach ($bookCollection->getSeries('Harry Potter')) {
24 // Do something with just one serie
25 }
26
27 $it = $bookCollection->getTopRatedBooks();
28 $it2 = new LimitIterator($it, 0, 5);
29 foreach ($it2 as $book) {
30 // Do something with the top 5
31 }
32
33 $it = $bookCollection->getTopRatedBooks();
34 $it2 = new RegexIterator($it, '/(gray|colour)/');
35 foreach ($it2 as $book) {
36 // Do something with all books that have 'gray' or 'colour' in the title
37 }