Making a PHP object behave like an array?

前端 未结 2 613
忘了有多久
忘了有多久 2020-12-23 22:12

I\'d like to be able to write a PHP class that behaves like an array and uses normal array syntax for getting & setting.

For example (where Foo is a PHP class of

2条回答
  •  [愿得一人]
    2020-12-23 22:30

    If you extend ArrayObject or implement ArrayAccess then you can do what you want.

    • ArrayObject
    • ArrayAccess

提交回复
热议问题