Treat a PHP class that implements Iterator as an array

后端 未结 3 893
长发绾君心
长发绾君心 2020-12-16 22:34

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

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 23:27

    Implement ArrayAccess in your class.

    See the documentation here: http://www.php.net/arrayaccess

提交回复
热议问题