hphp/hack/manual/apis/Classes/HH/Vector/index.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Vector is a stack-like collection
HHVM provides a native implementation for this class. The PHP class definition below is not actually used at run time; it is simply provided for the typechecker and for developer reference.
Like all objects in PHP, Vectors have reference-like semantics. When a
caller passes a Vector to a callee, the callee can modify the Vector and
the caller will see the changes. Vectors do not have "copy-on-write"
semantics.
Vectors only support integer keys. If a non-integer key is used, an
exception will be thrown.
Vectors support $m[$k] style syntax for getting and setting values by
key. Vectors also support isset($m[$k]) and empty($m[$k]) syntax, and
they provide similar semantics as arrays. Elements can be added to a
Vector using $m[] = .. syntax.
Vectors do not support iterating while new elements are being added or
elements are being removed. When a new element is added or removed, all
iterators that point to the Vector shall be considered invalid.
namespace HH;
final class Vector implements \MutableVector<Tv> {...}
::fromArray(darray<arraykey, Tv> $arr): Vector<Tv>Vector containing the values from the specified array::fromItems(?Traversable<Tv> $iterable): Vector<Tv>Vector from the given Traversable, or an empty Vector if
null is passed::fromKeysOf<Tk as arraykey>(?KeyedContainer<Tk, mixed> $container): Vector<Tk>Vector from the keys of the specified container->__construct(?Traversable<Tv> $iterable = NULL): voidVector from the given Traversable, or an empty Vector
if null is passed->__toString(): stringstring version of the current Vector, which is "Vector"->add(Tv $value): Vector<Tv>Vector, assigning it the next
available integer key->addAll(?Traversable<Tv> $iterable): Vector<Tv>Traversable, append a value into this
Vector, assigning the next available integer key for each->addAllKeysOf(?KeyedContainer<Tv, mixed> $container): Vector<Tv>Vector->append(mixed $value): this->at(int $key): TvVector->clear(): Vector<Tv>Vector->concat<Tu super Tv>(Traversable<Tu> $traversable): Vector<Tu>Vector that is the concatenation of the values of the current
Vector and the values of the provided Traversable->contains(mixed $key): bool->containsKey(mixed $key): boolVector->count(): intVector->filter((function(Tv): bool) $callback): Vector<Tv>Vector containing the values of the current Vector that meet
a supplied condition->filterWithKey((function(int, Tv): bool) $callback): Vector<Tv>Vector containing the values of the current Vector that meet
a supplied condition applied to its keys and values->firstKey(): ?intVector->firstValue(): ?TvVector->get(int $key): ?TvVector->getIterator(): KeyedIterator<int, Tv>Vector->immutable(): ImmVector<Tv>ImmVector) of the current Vector->isEmpty(): boolVector is empty->items(): Iterable<Tv>Iterable view of the current Vector->keys(): Vector<int>Vector containing the keys of the current Vector->lastKey(): ?intVector->lastValue(): ?TvVector->lazy(): KeyedIterable<int, Tv>Vector->linearSearch(mixed $search_value): int->map<Tu>((function(Tv): Tu) $callback): Vector<Tu>Vector containing the results of applying an operation to each
value in the current Vector->mapWithKey<Tu>((function(int, Tv): Tu) $callback): Vector<Tu>Vector containing the results of applying an operation to each
key/value pair in the current Vector->pop(): TvVector and return it->removeKey(int $key): Vector<Tv>Vector->reserve(int $sz): void->resize(int $size, Tv $value): voidVector->reverse(): voidVector in place->set(int $key, Tv $value): Vector<Tv>Vector with the specified key,
overwriting the previous value associated with the key->setAll(?KeyedTraversable<int, Tv> $iterable): Vector<Tv>Traversable, stores a value into the
current Vector associated with each key, overwriting the previous value
associated with the key->shuffle(): voidVector randomly in place->skip(int $n): Vector<Tv>Vector containing the values after the $n-th element of the
current Vector->skipWhile((function(Tv): bool) $fn): Vector<Tv>Vector containing the values of the current Vector starting
after and including the first value that produces false when passed to
the specified callback->slice(int $start, int $len): Vector<Tv>Vector starting from a given key up to,
but not including, the element at the provided length from the starting key->splice(int $offset, ?int $len = NULL): voidVector in place->take(int $n): Vector<Tv>Vector containing the first $n values of the current
Vector->takeWhile((function(Tv): bool) $callback): Vector<Tv>Vector containing the values of the current Vector up to but
not including the first value that produces false when passed to the
specified callback->toDArray(): darray<int, Tv>->toImmMap(): ImmMap<int, Tv>ImmMap) based on the values of
the current Vector->toImmSet(): ImmSet<Tv>ImmSet) based on the values of the current
Vector->toImmVector(): ImmVector<Tv>ImmVector) of the current Vector->toKeysArray(): varray<int>array whose values are the keys from the current Vector->toMap(): Map<int, Tv>Map based on the values of the current Vector->toSet(): Set<Tv>Set based on the values of the current Vector->toVArray(): varray<Tv>->toValuesArray(): varray<Tv>array containing the values from the current Vector->toVector(): Vector<Tv>Vector->values(): Vector<Tv>Vector containing the values of the current Vector->zip<Tu>(Traversable<Tu> $traversable): Vector<Pair<Tv, Tu>>Vector where each element is a Pair that combines the
element of the current Vector and the provided Traversable