Quantcast
Channel: Treat a PHP class that implements Iterator as an array - Stack Overflow
Browsing latest articles
Browse All 4 View Live

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 Article



Answer 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 Article

Answer 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 Article

Treat 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
Browsing latest articles
Browse All 4 View Live




Latest Images