HH\Map::setAll
For every element in the provided Traversable
, stores a value into the
current Map
associated with each key, overwriting the previous value
associated with the key
public function setAll(
?KeyedTraversable<Tk, Tv> $iterable,
): Map<Tk, Tv>;
This method is equivalent to Map::addAll()
. If a key to set does not
exist in the Map that does exist in the Traversable
, it is created. This
is inconsistent with, for example, the method Vector::setAll()
where if
a key is not found, an exception is thrown.
Future changes made to the current Map
ARE reflected in the returned
Map
, and vice-versa.
Parameters
?
KeyedTraversable<Tk,
Tv> $iterable
Returns
Map<Tk,
Tv>
- Returns itself.
Examples
This example shows how setAll()
can be used with any KeyedTraversable
:
$m = Map {
'red' => '#ff0000',
'green' => '#00ff00',
'blue' => '#0000ff',
'yellow' => '#ffff00',
};
// Set the values at keys 'red' and 'green'
$m->setAll(Map {
'red' => 'rgb(255, 0, 0)',
'green' => 'rgb(0, 255, 0)',
});
// Set the values at keys 'blue' and 'yellow' with an associative array
$m->setAll(darray[
'blue' => 'rgb(0, 0, 255)',
'yellow' => 'rgb(255, 255, 0)',
]);
\var_dump($m);