differenceByKey
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
public function differenceByKey(
KeyedTraversable<Tk, Tv> $traversable,
): Map<Tk, Tv>;
Parameters
KeyedTraversable<Tk,Tv> $traversable- TheKeyedTraversableon which to compare the keys.
Returns
Map<Tk,Tv>- AMapcontaining the keys (and associated values) of the currentMapthat are not in theKeyedTraversable.
Examples
This example shows how differenceByKey can be used to get a new Map with some keys excluded:
$m = Map {
'red' => '#ff0000',
'green' => '#00ff00',
'blue' => '#0000ff',
'yellow' => '#ffff00',
'purple' => '#663399',
};
$m2 = $m->differenceByKey(Set {'red', 'green', 'blue'});
\var_dump($m2);