A vector is a linear data structure where values are stored sequentially and also the size grows and shrinks automatically. Vector is one of the most efficient linear data structures as the value's index is mapped directly with the index of the buffer and allows faster access. DS vector class allows us to use the PHP array syntax for operations, but internally, it has less memory consumption than PHP array. It has constant time operations for push, pop, get, and set. Here is an example of vector:
$vector = new \Ds\Vector(["a", "b", "c"]); echo $vector->get(1)."\n"; $vector[1] = "d"; echo $vector->get(1)."\n"; $vector->push('f'); echo "Size of vector: ".$vector->count();
As we can see from the preceding code, we can define a vector ...