class ArrayIterator implements SeekableIterator, ArrayAccess, Serializable, Countable (View source)

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

Constants

STD_PROP_LIST

ARRAY_AS_PROPS

Methods

__construct(TValue>|object $array = [], int $flags = 0, $iterator_class = null)

Construct an ArrayIterator

bool
offsetExists(TKey $key)

Check if offset exists

TValue
offsetGet(TKey $key)

Get value for an offset

void
offsetSet(TKey $key, TValue $value)

Set value for an offset

void
offsetUnset(TKey $key)

Unset value for an offset

void
append(TValue $value)

Append an element

TValue>
getArrayCopy()

Get array copy

int<0, max>
count()

Count elements

int
getFlags()

Get flags

void
setFlags(int $flags)

Set behaviour flags

asort(int $flags = SORT_REGULAR)

Sort array by values

ksort(int $flags = SORT_REGULAR)

Sort array by keys

uasort(TValue): int $callback)

User defined sort

uksort(TKey): int $callback)

User defined sort

natsort()

Sort an array naturally

natcasesort()

Sort an array naturally, case insensitive

void
unserialize(string $data)

Unserialize

string|null
serialize()

Serialize

void
rewind()

Rewind array back to the start

TValue
current()

Return current array entry

TKey|null
key()

Return current array key

void
next()

Move to next entry

bool
valid()

Check whether array contains more entries

void
seek(int $offset)

Seek to position

array
__debugInfo()

No description

array
__serialize()

No description

__unserialize(array $data)

No description

Details

__construct(TValue>|object $array = [], int $flags = 0, $iterator_class = null)

Construct an ArrayIterator

Parameters

TValue>|object $array

The array or object to be iterated on.

int $flags

Flags to control the behaviour of the ArrayObject object.

$iterator_class

See also

ArrayObject::setFlags

bool offsetExists(TKey $key)

Check if offset exists

Parameters

TKey $key

The offset being checked.

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

TValue offsetGet(TKey $key)

Get value for an offset

Parameters

TKey $key

The offset to get the value from.

Return Value

TValue

Can return all value types.

void offsetSet(TKey $key, TValue $value)

Set value for an offset

Parameters

TKey $key

The index to set for.

TValue $value

The value to set.

Return Value

void

void offsetUnset(TKey $key)

Unset value for an offset

Parameters

TKey $key

The offset to unset.

Return Value

void

void append(TValue $value)

Append an element

Parameters

TValue $value

The value to append.

Return Value

void

TValue> getArrayCopy()

Get array copy

Return Value

TValue>

A copy of the array, or array of public properties if ArrayIterator refers to an object.

int<0, max> count()

Count elements

Return Value

int<0, max>

The custom count as an integer.

The return value is cast to an integer.

int getFlags()

Get flags

Return Value

int

The current flags.

void setFlags(int $flags)

Set behaviour flags

Parameters

int $flags

A bitmask as follows: 0 = Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.). 1 = Array indices can be accessed as properties in read/write.

Return Value

void

asort(int $flags = SORT_REGULAR)

Sort array by values

Parameters

int $flags

ksort(int $flags = SORT_REGULAR)

Sort array by keys

Parameters

int $flags

uasort(TValue): int $callback)

User defined sort

Parameters

TValue): int $callback

The compare function used for the sort.

uksort(TKey): int $callback)

User defined sort

Parameters

TKey): int $callback

The compare function used for the sort.

natsort()

Sort an array naturally

natcasesort()

Sort an array naturally, case insensitive

void unserialize(string $data)

Unserialize

Parameters

string $data

The string representation of the object.

Return Value

void

string|null serialize()

Serialize

Return Value

string|null

The string representation of the object or null

void rewind()

Rewind array back to the start

Return Value

void

Any returned value is ignored.

TValue current()

Return current array entry

Return Value

TValue

Can return any type.

TKey|null key()

Return current array key

Return Value

TKey|null

TKey on success, or null on failure.

void next()

Move to next entry

Return Value

void

Any returned value is ignored.

bool valid()

Check whether array contains more entries

Return Value

bool

The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.

void seek(int $offset)

Seek to position

Parameters

int $offset

The position to seek to.

Return Value

void

array __debugInfo()

Since: 7.4

No description

Return Value

array

array __serialize()

Since: 7.4

No description

Return Value

array

__unserialize(array $data)

Since: 7.4

No description

Parameters

array $data