php8.5
Home/ Manual/ reference / ds/ The Sequence interface

The Sequence interface

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].

Intro

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:

  • Wherever you would use an array as a list (not concerned with keys).
  • A more efficient alternative to SplDoublyLinkedList and SplFixedArray.

Interfacesynopsis

implements Ds\Sequence extends Ds\Collection implements ArrayAccess { }

Changelog

VersionDescription
PECL ds 1.3.0The interface now extends ArrayAccess.

Sequence

Source: reference/ds/ds.sequence.xml · from the official PHP manual (php/doc-en)