[lang-ref] ( dict_key_exists ) ( php )
<?php
public function testDictKeyExists(): void
{
// array_key_exists($k, $d)
$d = [ 'A' => 1, 'B' => 2, 'C' => 3 ];
$this->assertTrue(array_key_exists('A', $d));
$this->assertFalse(array_key_exists('D', $d));
}
<?php
public function testDictKeyExistsAlternative(): void
{
// isset($d[$k])
$d = [ 'A' => 1, 'B' => 2, 'C' => 3 ];
$this->assertTrue(isset($d['A'])); // key exists and value is not null
$this->assertFalse(isset($d['D'])); // key does not exist
}