What are the benefits of using SPL ArrayObject, ArrayIterator, RecursiveArrayIterator instead of regular arrays?

半腔热情 提交于 2019-11-30 12:14:56

The primary benefit you're looking at efficient data access mostly in the area of readability. This way you can use object just like an array in a foreach so a closer interaction with PHP.

a) The way you reduce memory usage is by not making a copy of the array but if done properly in the engine then it should be a new reference until the array is modified then it's actually copied.

b) Essentially

A good example of this would be the SimpleXML extension. The PHP/XML object you're interacting with also acts like an array which makes it efficient to use because you can just foreach or access one of the elements within the list. You don't have to grab an array from the object and then iterate over and do something else with it if you want the tag name or an attribute.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!