search

Home  >  Q&A  >  body text

isset和array_key_exists有什么区别?

判断是否存在有的时候用isset吗? 有点时候用array_key_exists。这俩有什么区别呢?

phpcn_u233phpcn_u2332977 days ago1230

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:50:06

    What is the difference between

    isset and array_key_exists? -PHP Chinese website Q&A-What is the difference between isset and array_key_exists? -PHP Chinese website Q&A

    Take a look around and learn.

    reply
    0
  • phpcn_u233

    phpcn_u2332017-01-06 15:13:24

    1.对于数组值的判断不同,对于值为null或''或false,isset返回false,array_key_exists返回true;

     2. 执行效率不同,isset是内建运算符,array_key_exists是php内置函数,isset要快一些。请参考:PHP 函数实现原理及性能分析 

     3.当用isset访问一个不存在索引数组值时,不会引起一个E_NOTICE的php错误消息;

     4.array_key_exists 会调用get_defined_vars判断数组变量是否存在,isset不用;

    reply
    0
  • Cancelreply