What’s the difference between isset() and array_key_exists()?

Technology CommunityCategory: PHPWhat’s the difference between isset() and array_key_exists()?
VietMX Staff asked 4 years ago
  • array_key_exists will tell you if a key exists in an array and complains when $a does not exist.
  • isset will only return true if the key/variable exists and is not nullisset doesn’t complain when $a does not exist.

Consider:

$a = array('key1' => 'Foo Bar', 'key2' => null);

isset($a['key1']);             // true
array_key_exists('key1', $a);  // true

isset($a['key2']);             // false
array_key_exists('key2', $a);  // true