Use array_key_exists()
instead of isset()
, because isset()
will return false
if the variable is null
, whereas array_key_exists()
just checks if the key exists in the array:
function check($array, $key)
{
if(array_key_exists($key, $array)) {
if (is_null($array[$key])) {
echo $key . ' is null';
} else {
echo $key . ' is set';
}
}
}