ArrayIterator 類

(PHP 5, PHP 7, PHP 8)

簡介

這個(gè)迭代器允許在遍歷數(shù)組和對象時(shí)刪除和更新值與鍵。

當(dāng)你想多次遍歷相同數(shù)組時(shí)你需要實(shí)例化 ArrayObject,然后讓這個(gè)實(shí)例創(chuàng)建一個(gè) ArrayIterator 實(shí)例。 當(dāng)你想遍歷相同數(shù)組時(shí)多次你需要實(shí)例 ArrayObject 并且讓這個(gè)實(shí)例創(chuàng)建一個(gè) ArrayIterator 實(shí)例,然后使用 foreach 或者手動(dòng)調(diào)用 getIterator() 方法。

類摘要

class ArrayIterator implements SeekableIterator, ArrayAccess, Serializable, Countable {
/* 常量 */
const int STD_PROP_LIST = 1;
const int ARRAY_AS_PROPS = 2;
/* 方法 */
public __construct(array|object $array = [], int $flags = 0)
public append(mixed $value): void
public asort(int $flags = SORT_REGULAR): bool
public count(): int
public current(): mixed
public getArrayCopy(): array
public getFlags(): int
public key(): string|int|null
public ksort(int $flags = SORT_REGULAR): bool
public natcasesort(): bool
public natsort(): bool
public next(): void
public offsetExists(mixed $key): bool
public offsetGet(mixed $key): mixed
public offsetSet(mixed $key, mixed $value): void
public offsetUnset(mixed $key): void
public rewind(): void
public seek(int $offset): void
public serialize(): string
public setFlags(int $flags): void
public uasort(callable $callback): bool
public uksort(callable $callback): bool
public unserialize(string $data): void
public valid(): bool
}

預(yù)定義常量

ArrayIterator 標(biāo)記

ArrayIterator::STD_PROP_LIST

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

ArrayIterator::ARRAY_AS_PROPS

可以通過屬性訪問條目(讀寫都支持)。

目錄