HH\Map::removeKey

Removes the specified key (and associated value) from the current Map

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

This method is interchangeable with remove().

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

Parameters

  • Tk $key

Returns

Examples

Since Map::removeKey() returns a shallow copy of $m itself, you can chain a bunch of removeKey() calls together.

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

// Remove key 'red'
$m->removeKey('red');
\var_dump($m);

// Remove keys 'green' and 'blue'
$m->removeKey('green')->removeKey('blue');
\var_dump($m);