Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sequence

A sequence is an ordered collection of values accessed by integer index starting from 0. PHP arrays natively act as sequences when keys are consecutive integers. The ds extension provides a dedicated Ds\Sequence interface implemented by Ds\Vector and Ds\Deque.

Unlike sets or maps, sequences allow duplicate values and maintain insertion order.

<?php

use Ds\Vector;

$seq = new Vector([1, 2, 3, 4]);
$seq->push(5);
echo $seq->get(2); // 3
echo $seq->count(); // 5

?>

Documentation

See Also