HH\Pair::getIterator

Returns an iterator that points to beginning of the current Pair

Description

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

Return Values

Examples

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

<?hh

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

$p = Pair {'foo', -1.5};

// Get a KeyedIterator for the Pair
$iterator = $p->getIterator();

// Print both keys and values
while ($iterator->valid()) {
  echo $iterator->key().' => '.$iterator->current()."\n";
  $iterator->next();
}
Output
0 => foo
1 => -1.5