ArrayIterator 类

(PHP 5, PHP 7, PHP 8)

简介

允许在迭代数组和对象时删除元素以及更新值或键。

当你想多次遍历相同数组时你需要实例化 ArrayObject,然后让这个实例创建一个 ArrayIterator 实例。 当你想遍历相同数组时多次你需要实例 ArrayObject 并且让这个实例创建一个 ArrayIterator 实例,然后使用 foreach 或者手动调用 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

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

ArrayIterator::ARRAY_AS_PROPS

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

目录

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top