HH\Vector::addAllKeysOf

Adds the keys of the specified container to the current Vector.

Description

public function addAllKeysOf(
  ?KeyedContainer<Tv,Tv2> $container,
): Vector<Tv>

Adds the keys of the specified container to the current Vector.

If a key of the specified container are not integers, then it adds the next available integer key in this Vector and makes that key the value.

Future changes made to the current Vector ARE reflected in the returned Vector, and vice-versa.

Parameters

  • ?KeyedContainer<Tv,Tv2> $container - The container with the new keys to add.

Return Values

Examples

This example adds string keys from a Map to a Vector as its values:

<?hh

namespace Hack\UserDocumentation\API\Examples\Vector\AddAllKeysOf\Strings;

$fruit_calories = Map {
  'apple' => 95,
  'orange' => 45,
};

$vegetable_calories = array(
  'cabbage' => 176,
  'potato' => 163,
);

$food_names = Vector {};

// Add the keys from a Map
$food_names->addAllKeysOf($fruit_calories);

// Add the keys from an associative array
$food_names->addAllKeysOf($vegetable_calories);

var_dump($food_names);
Output
object(HH\Vector)#2 (4) {
  [0]=>
  string(5) "apple"
  [1]=>
  string(6) "orange"
  [2]=>
  string(7) "cabbage"
  [3]=>
  string(6) "potato"
}

This example adds int keys from a Map to a Vector as its values:

<?hh

namespace Hack\UserDocumentation\API\Examples\Vector\AddAllKeysOf\Ints;

$uploaders_by_id = Map {
  4993063 => 'Amy Smith',
  9361760 => 'John Doe',
};

$commenters_by_id = array(
  7424854 => 'Jane Roe',
  5740542 => 'Joe Bloggs',
);

$all_ids = Vector {};

// Add the keys from a Map
$all_ids->addAllKeysOf($uploaders_by_id);

// Add the keys from an associative array
$all_ids->addAllKeysOf($commenters_by_id);

var_dump($all_ids);
Output
object(HH\Vector)#2 (4) {
  [0]=>
  int(4993063)
  [1]=>
  int(9361760)
  [2]=>
  int(7424854)
  [3]=>
  int(5740542)
}