Back to Hhvm

DifferenceByKey

hphp/hack/manual/apis/Classes/HH/Map/differenceByKey.md

latest1.5 KB
Original Source

:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::

Returns a new Map with the keys that are in the current Map, but not in the provided KeyedTraversable

Hack
public function differenceByKey(
  KeyedTraversable<Tk, Tv> $traversable,
): Map<Tk, Tv>;

Parameters

Returns

Examples

This example shows how differenceByKey can be used to get a new Map with some keys excluded:

basic-usage.hack
$m = Map {
  'red' => '#ff0000',
  'green' => '#00ff00',
  'blue' => '#0000ff',
  'yellow' => '#ffff00',
  'purple' => '#663399',
};

$m2 = $m->differenceByKey(Set {'red', 'green', 'blue'});

\var_dump($m2);
<!-- HHAPIDOC -->