HH\Map::remove

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

Description

public function remove(
  Tk $k,
): Map<Tk,Tv>

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

This method is interchangeable with removeKey().

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

Parameters

  • Tk $k - The key to remove.

Return Values

Examples

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

<?hh

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

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

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

// Remove keys 'green' and 'blue'
$m->remove('green')->remove('blue');
var_dump($m);
Output
object(HH\Map)#1 (3) {
  ["green"]=>
  string(7) "#00ff00"
  ["blue"]=>
  string(7) "#0000ff"
  ["yellow"]=>
  string(7) "#ffff00"
}
object(HH\Map)#1 (1) {
  ["yellow"]=>
  string(7) "#ffff00"
}