difference between isset() and array_key_exists() function in php?
The main difference between isset() and array_key_exists() function is that the array_key_exists() function will definitely tells if a key exists in an array.
1. Code:
<?php
$array = array(
'name' => null,
);
echo"Result for array_key_exists():"."<br>";
echo array_key_exists('name', $array)
? 'array key exists' : 'array key does not exist';
echo"<br>"."Result for isset():"."<br>";
echo isset($array['name']) ? 'array is set.' :
'array is not set.';
?>
2. Example:
Input:
$array = array(
'name' => null,
);
Output:
Result for array_key_exists(): array key exists Result for isset(): array is not set.
3. Difference between isset() and array_key_exists():
The main difference between isset() and array_key_exists() function is that the array_key_exists() function will definitely tells if a key exists in an array, whereas isset() will only return true if the key/variable exists and is not null. Also isset() doesn’t render error when array/variable does not exist, while array_key_exists does.