HH\Map::containsKey

Determines if the specified key is in the current Map

Description

public function containsKey<Tu super Tk>(
  Tu $k,
): bool

This function is interchangeable with contains().

Parameters

  • $k - The key to check.

Return Values

  • bool - true if the specified key is present in the current Map; returns false otherwise.

Examples

<?hh

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

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

// Prints "true", since key "red" is the first key
var_dump($m->containsKey('red'));

// Prints "true", since key "yellow" is the last key
var_dump($m->containsKey('yellow'));

// Prints "false", since key "blurple" isn't in the Map
var_dump($m->containsKey('blurple'));
Output
bool(true)
bool(true)
bool(false)