code_junkie

PHP: Implementing the SeekableIterator interface

Nov 13th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class BookShelf implements ArrayAccess, Countable, SeekableIterator {
  2. protected $_books = array(...);
  3. protected $_magazines = array(...);
  4.  
  5. /**** CLASS CONTENT HERE ****/
  6. }
  7.  
  8. $shelf = new BookShelf();
  9.  
  10. // Loops through both arrays, first books (if any) and then magazines (if any)
  11. foreach($shelf as $item) {
  12. echo $item;
  13. }
  14.  
  15. count($this->_books);
  16.  
  17. $this->_books[$index];
  18.  
  19. $this->_magazines[$index-count($this->_books)]
Add Comment
Please, Sign In to add comment