大网数据广告活动
PHP 语言与运行手册

The Sequence interface

· 52CE 我爱测

A Sequence describes the behaviour of values arranged in a single, linear dimension. Some languages refer to this as a "List". It’s similar to an array that uses incremental integer keys, with the exception of a few characteristics: Values will always be indexed as [0, 1, 2, …, s

The Sequence interface

(PECL ds >= 1.0.0)

Introduction

A Sequence describes the behaviour of values arranged in a single, linear dimension. Some languages refer to this as a "List". It’s similar to an array that uses incremental integer keys, with the exception of a few characteristics:

  • Values will always be indexed as [0, 1, 2, …, size - 1].
  • Only allowed to access values by index in the range [0, size - 1].

Use cases:

Interface synopsis

interface Ds\Sequence extends Ds\Collection, ArrayAccess {
/* Methods */
abstract public function allocate(int $capacity): void
abstract public function apply(callable $callback): void
abstract public function capacity(): int
abstract public function contains(mixed ...$values): bool
abstract public function filter(callable $callback = ?): Ds\Sequence
abstract public function find(mixed $value): mixed
abstract public function first(): mixed
abstract public function get(int $index): mixed
abstract public function insert(int $index, mixed ...$values): void
abstract public function join(string $glue = ?): string
abstract public function last(): mixed
abstract public function map(callable $callback): Ds\Sequence
abstract public function merge(mixed $values): Ds\Sequence
abstract public function pop(): mixed
abstract public function push(mixed ...$values): void
abstract public function reduce(callable $callback, mixed $initial = ?): mixed
abstract public function remove(int $index): mixed
abstract public function reverse(): void
abstract public function reversed(): Ds\Sequence
abstract public function rotate(int $rotations): void
abstract public function set(int $index, mixed $value): void
abstract public function shift(): mixed
abstract public function slice(int $index, int $length = ?): Ds\Sequence
abstract public function sort(callable $comparator = ?): void
abstract public function sorted(callable $comparator = ?): Ds\Sequence
abstract public function sum(): int|float
abstract public function unshift(mixed $values = ?): void
/* Inherited methods */
public function Ds\Collection::clear(): void
public function Ds\Collection::isEmpty(): bool
public function Ds\Collection::toArray(): array
public function Countable::count(): int
public function ArrayAccess::offsetExists(mixed $offset): bool
public function ArrayAccess::offsetGet(mixed $offset): mixed
public function ArrayAccess::offsetSet(mixed $offset, mixed $value): void
public function ArrayAccess::offsetUnset(mixed $offset): void
}

Changelog

Version Description
PECL ds 1.3.0 The interface now extends ArrayAccess.

Table of Contents

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。