↧
Answer by vascowhite for Treat a PHP class that implements Iterator as an array
The purpose of the Iterator interface is to allow your object to be used in a foreach loop, it is not intended to make your object act like an array. If you want something that acts like an array, use...
View ArticleAnswer by Ronni Skansing for Treat a PHP class that implements Iterator as an...
From PHP Introduction Interface for external iterators or objects that can be iterated themselves internally. As you can see from the interface Table of Contents ¶ Iterator::current — Return the...
View ArticleAnswer by mark.sagikazar for Treat a PHP class that implements Iterator as an...
Implement ArrayAccess in your class. See the documentation here: http://www.php.net/arrayaccess
View ArticleTreat a PHP class that implements Iterator as an array
If I have a class that implements the Iterator interface, I can manually control how iteration in a foreach loop. But are there other ways in which I could make my object behave like an array? For...
View Article