For every element in the provided Traversable, add a key/value pair into the current Map


public function addAll(
  ?Traversable<Pair<Tk,Tv>> $it,
): Map<Tk, Tv>;

This method is equivalent to Map::setAll(). If a key in the Traversable exists in the Map, then the value associated with that key in the Map is overwritten.

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


  • ?Traversable<Pair<Tk,Tv>> $it

Return Values


The following example adds a collection of key-value pairs to the Map $m and also adds multiple collections of key-value pairs to $m through chaining. Since Map::addAll() returns a shallow copy of $m itself, you can chain a bunch of addAll() calls together.


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

$m = Map {};

// Add all the key-value pairs in an array
$m->addAll(array(Pair {'red', '#ff0000'}));

// Map::addAll returns the Map so it can be chained
$m->addAll(Vector {
  Pair {'green', '#00ff00'},
  Pair {'blue', '#0000ff'},
})->addall(ImmVector {
  Pair {'yellow', '#ffff00'},
  Pair {'purple', '#663399'},

object(HH\Map)#1 (5) {
  string(7) "#ff0000"
  string(7) "#00ff00"
  string(7) "#0000ff"
  string(7) "#ffff00"
  string(7) "#663399"