开发者

Are there any difference between the two statements?

开发者 https://www.devze.com 2022-12-21 16:55 出处:网络
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:
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

精彩评论

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