Consider these two examples...
$key = 'jim';
// example 1
if (isset($array[$key])) {
// ...
}
// example 2
if (array_key_exists($key, $array)) {
// ...
}
I'm interested to know if these two are better. I've been using the first example, but I've seen a lot of people on this site using the second example.
So, which one is better? hurry up? Clearer intention?
If you are interested in some of the tests I recently completed:
https://stackoverflow.com/a/21759158/520857
Summary:
isset()is faster, but not the same asarray_key_exists().array_key_exists()Purely checks if the key exists, even if the value isNULL.Given If the key exists and the value is
NULL,isset()will returnfalse.