ArrayIterator 类

(PHP 5, PHP 7, PHP 8)

简介

允许在遍历 arrays 或 objects 时删除元素,修改键或值。

要多次迭代同一个数组,建议实例化 ArrayObject 并使用 ArrayIterator 实例,当使用 foreach 隐式创建时,可以迭代内部存储的数组, 或者通过手动调用 ArrayObject::getIterator() 方法创建一个。

类摘要

class ArrayIterator implements SeekableIterator, ArrayAccess, Serializable, Countable {
/* 常量 */
public const int STD_PROP_LIST;
public const int ARRAY_AS_PROPS;
/* 方法 */
public __construct(array|object $array = [], int $flags = 0)
public append(mixed $value): void
public asort(int $flags = SORT_REGULAR): true
public count(): int
public current(): mixed
public getFlags(): int
public key(): string|int|null
public ksort(int $flags = SORT_REGULAR): true
public natcasesort(): true
public natsort(): true
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): true
public uksort(callable $callback): true
public unserialize(string $data): void
public valid(): bool
}

预定义常量

ArrayIterator 标记

ArrayIterator::STD_PROP_LIST

当以列表形式访问对象时(例如 var_dump()foreach 等),对象的属性将具有正常的功能。

ArrayIterator::ARRAY_AS_PROPS

可以通过属性访问条目(读写都支持)。

目录