AbstractArray
in package
implements
ArrayInterface
This class provides a basic implementation of `ArrayInterface`, to minimize the effort required to implement this interface.
Tags
Interfaces, Classes, Traits and Enums
- ArrayInterface
- `ArrayInterface` provides traversable array functionality to data types.
Table of Contents
- $data : array<array-key, T>
- The items of this array.
- __construct() : mixed
- Constructs a new array object.
- __serialize() : array<array-key, T>
- Returns data suitable for PHP serialization.
- __unserialize() : void
- Adds unserialized data to the object.
- clear() : void
- Removes all items from this array.
- count() : int
- Returns the number of items in this array.
- getIterator() : Traversable<array-key, T>
- Returns an iterator for this array.
- isEmpty() : bool
- Returns `true` if this array is empty.
- offsetExists() : bool
- Returns `true` if the given offset exists in this array.
- offsetGet() : T|null
- Returns the value at the specified offset.
- offsetSet() : void
- Sets the given value to the given offset in the array.
- offsetUnset() : void
- Removes the given offset and its value from the array.
- serialize() : string
- Returns a serialized string representation of this array object.
- toArray() : array<array-key, T>
- Returns a native PHP array representation of this array object.
- unserialize() : void
- Converts a serialized string representation into an instance object.
Properties
$data
The items of this array.
protected
array<array-key, T>
$data
= []
Methods
__construct()
Constructs a new array object.
public
__construct([array<array-key, T> $data = [] ]) : mixed
Parameters
- $data : array<array-key, T> = []
-
The initial items to add to this array.
Return values
mixed —__serialize()
Returns data suitable for PHP serialization.
public
__serialize() : array<array-key, T>
Tags
Return values
array<array-key, T> —__unserialize()
Adds unserialized data to the object.
public
__unserialize(array<array-key, T> $data) : void
Parameters
- $data : array<array-key, T>
Return values
void —clear()
Removes all items from this array.
public
clear() : void
Return values
void —count()
Returns the number of items in this array.
public
count() : int
Tags
Return values
int —getIterator()
Returns an iterator for this array.
public
getIterator() : Traversable<array-key, T>
Tags
Return values
Traversable<array-key, T> —isEmpty()
Returns `true` if this array is empty.
public
isEmpty() : bool
Return values
bool —offsetExists()
Returns `true` if the given offset exists in this array.
public
offsetExists(string|int $offset) : bool
Parameters
- $offset : string|int
-
The offset to check.
Tags
Return values
bool —offsetGet()
Returns the value at the specified offset.
public
offsetGet(string|int $offset) : T|null
Parameters
- $offset : string|int
-
The offset for which a value should be returned.
Tags
Return values
T|null —the value stored at the offset, or null if the offset does not exist.
offsetSet()
Sets the given value to the given offset in the array.
public
offsetSet(string|int|null $offset, T $value) : void
Parameters
- $offset : string|int|null
-
The offset to set. If
null
, the value may be set at a numerically-indexed offset. - $value : T
-
The value to set at the given offset.
Tags
Return values
void —offsetUnset()
Removes the given offset and its value from the array.
public
offsetUnset(string|int $offset) : void
Parameters
- $offset : string|int
-
The offset to remove from the array.
Tags
Return values
void —serialize()
Returns a serialized string representation of this array object.
public
serialize() : string
Tags
Return values
string —a PHP serialized string.
toArray()
Returns a native PHP array representation of this array object.
public
toArray() : array<array-key, T>
Tags
Return values
array<array-key, T> —unserialize()
Converts a serialized string representation into an instance object.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
-
A PHP serialized string to unserialize.