The ArrayIterator class

(PHP 5, PHP 7, PHP 8)

Introduction

Allows the removal of elements, and the modification of keys or values while iterating over Arrays or 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.

Class synopsis

classArrayIteratorimplementsSeekableIterator, ArrayAccess, Serializable, Countable {
publicconstintSTD_PROP_LIST;
publicconstintARRAY_AS_PROPS;
public__construct(array|object$array = [], int$flags = 0)
publicappend(mixed$value): void
publicasort(int$flags = SORT_REGULAR): true
publiccount(): int
publiccurrent(): mixed
publicgetFlags(): int
publickey(): string|int|null
publicksort(int$flags = SORT_REGULAR): true
publicnatcasesort(): true
publicnatsort(): true
publicnext(): void
publicoffsetExists(mixed$key): bool
publicoffsetGet(mixed$key): mixed
publicoffsetSet(mixed$key, mixed$value): void
publicoffsetUnset(mixed$key): void
publicrewind(): void
publicseek(int$offset): void
publicserialize(): string
publicsetFlags(int$flags): void
publicuasort(callable$callback): true
publicuksort(callable$callback): true
publicunserialize(string$data): void
publicvalid(): bool
}

Predefined Constants

ArrayIterator Flags

ArrayIterator::STD_PROP_LIST

Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.).

ArrayIterator::ARRAY_AS_PROPS

Entries can be accessed as properties (read and write).

Table of Contents

To Top