HH\Vector::getIterator

Returns an iterator that points to beginning of the current Vector

Description

public function getIterator(): KeyedIterator<int, Tv>

Return Values

Examples

This example shows how to get an iterator from a Vector and how to consume it:

<?hh

namespace Hack\UserDocumentation\API\Examples\Vector\GetIterator;

$v = Vector {'red', 'green', 'blue', 'yellow'};

// Get an iterator for the Vector of colors
$iterator = $v->getIterator();

// Print each color using the iterator
while ($iterator->valid()) {
  echo $iterator->current()."\n";
  $iterator->next();
}
Output
red
green
blue
yellow