ArrayAccessTrait
ArrayAccessTrait provides the implementation for [[\IteratorAggregate]], [[\ArrayAccess]] and [[\Countable]].
Note that ArrayAccessTrait requires the class using it contain a property named data
which should be an array.
The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.
Tags
Table of Contents
Properties
- $data : array<string|int, mixed>
Methods
- count() : int
- Returns the number of data items.
- getIterator() : ArrayIterator
- Returns an iterator for traversing the data.
- offsetExists() : bool
- This method is required by the interface [[\ArrayAccess]].
- offsetGet() : mixed
- This method is required by the interface [[\ArrayAccess]].
- offsetSet() : mixed
- This method is required by the interface [[\ArrayAccess]].
- offsetUnset() : mixed
- This method is required by the interface [[\ArrayAccess]].
Properties
$data
public
array<string|int, mixed>
$data
Methods
count()
Returns the number of data items.
public
count() : int
This method is required by Countable interface.
Attributes
Return values
int —number of data elements.
getIterator()
Returns an iterator for traversing the data.
public
getIterator() : ArrayIterator
This method is required by the SPL interface [[\IteratorAggregate]].
It will be implicitly called when you use foreach
to traverse the collection.
Attributes
Return values
ArrayIterator —an iterator for traversing the cookies in the collection.
offsetExists()
This method is required by the interface [[\ArrayAccess]].
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
the offset to check on
Attributes
Return values
booloffsetGet()
This method is required by the interface [[\ArrayAccess]].
public
offsetGet(int $offset) : mixed
Parameters
- $offset : int
-
the offset to retrieve element.
Attributes
Return values
mixed —the element at the offset, null if no element is found at the offset
offsetSet()
This method is required by the interface [[\ArrayAccess]].
public
offsetSet(int $offset, mixed $item) : mixed
Parameters
- $offset : int
-
the offset to set element
- $item : mixed
-
the element value
Attributes
offsetUnset()
This method is required by the interface [[\ArrayAccess]].
public
offsetUnset(mixed $offset) : mixed
Parameters
- $offset : mixed
-
the offset to unset element