开发者

Are there any difference between the two statements?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜