HH\Map::toVector

Description

public function toVector(): Vector<Tv>

Returns a Vector with the values of the current Map.

Return Values

Examples

This example shows how toVector() returns a Vector of $m's values, so mutating this new Vector doesn't affect the original Map.

<?hh

namespace Hack\UserDocumentation\API\Examples\Map\ToVector;

$m = Map {
  'red' => '#ff0000',
  'green' => '#00ff00',
  'blue' => '#0000ff',
  'yellow' => '#ffff00',
};

// Make a deep Vector copy of the values of $m
$v = $m->toVector();

// Modify $v by adding an element
$v->add('#663399');
var_dump($v);

// The original Map $m doesn't include the value '#663399'
var_dump($m);
Output
object(HH\Vector)#2 (5) {
  [0]=>
  string(7) "#ff0000"
  [1]=>
  string(7) "#00ff00"
  [2]=>
  string(7) "#0000ff"
  [3]=>
  string(7) "#ffff00"
  [4]=>
  string(7) "#663399"
}
object(HH\Map)#1 (4) {
  ["red"]=>
  string(7) "#ff0000"
  ["green"]=>
  string(7) "#00ff00"
  ["blue"]=>
  string(7) "#0000ff"
  ["yellow"]=>
  string(7) "#ffff00"
}