array_key_ex开发者_如何学Cists($name, $defaults)
isset($defaults[$name])
Yes, there is a difference. isset
returns false if the value is null while array_key_exists
doesn’t:
$defaults = array('foobar' => null);
var_dump(array_key_exists('foobar', $defaults)); // bool(true)
var_dump(isset($defaults['foobar'])); // bool(false)
So you should always use array_key_exists
for array keys unless you don’t want to make a difference whether an array item exists or is null.
Here is a quick comment from the PHP manual talking about the performance differences between the two! But they do the same thing :-\
Strike that, I'm an idiot.
精彩评论