Difference between ArrayIterator, ArrayObject and Array in PHP

后端 未结 6 1778
一整个雨季
一整个雨季 2021-02-01 16:19

Can somebody explain clearly the fundamental differences between ArrayIterator, ArrayObject and Array in PHP in terms of functionality and

6条回答
  •  萌比男神i
    2021-02-01 17:03

    • Arrays

    An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

    • The ArrayObject class

    This class allows objects to work as arrays.

    • The ArrayIterator class

    This iterator allows to unset and modify values and keys while iterating over Arrays and Objects.

    When you want to iterate over the same array multiple times you need to instantiate ArrayObject and let it create ArrayIterator instances that refer to it either by using foreach or by calling its getIterator() method manually.

提交回复
热议问题