Home  >  Q&A  >  body text

isset和exists有什么区别?

如题,之前判断是否存在不是用isset吗? 现在用exists 。。。 这俩有什么区别呢?

phpcn_u226phpcn_u2262765 days ago799

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:15:31

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

    Please watch and learn.

    reply
    0
  • 阿神

    阿神2016-12-20 16:36:54

    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