isset和exists有什么区别?
phpcn_u226
phpcn_u226 2016-12-20 16:36:39
0
2
809

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

phpcn_u226
phpcn_u226

reply all(2)
数据分析师

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.

阿神

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不用;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!