Stores a value into the current Map with the specified key, overwriting the previous value associated with the key

public function set(
  Tk $key,
  Tv $value,
): Map<Tk, Tv>;

This method is equivalent to Map::add(). If the key to set does not exist, it is created. This is inconsistent with, for example, Vector::set() where if the key is not found, an exception is thrown.

$map->set($k,$v) is equivalent to $map[$k] = $v (except that set() returns the current Map).

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


  • Tk $key
  • Tv $value

Return Values