STUDY WHILE YOU ARE BORING


  • 首頁

  • 搜索

  • 技术

  • Tags

  • 关于我

php isset 的坑 - 正确判断数组里面的键是否存在

發表於 August 13, 2014   |   作者: Tim   |   分类: 技术   |   评论

习惯了使用isset 判断数组里面的键是否存在,今天遇到一个很纠结的情况,百思不得其解。

通常我们会这样做

`if (isset($_POST['hello'])) xxx ;

if (isset($arr['id']) xxx ;`

但是今天发现,明明 $arr 里面是有 id 这个键的,isset($arr['id']) 返回 false

重新查询了文档
7C604713-1A9C-40EA-A184-0195846CD9F4.png

注意到了一个细节:

并且不是 NULL

终于找到了真凶,如果数组中存在这个键,但是对应的值是null 也会返回false。

那么我们怎么解决呢?

bool array_key_exists ( mixed $key , array $search )

php, isset, array_key_exists
深入理解ob_flush和flush的区别
UPS Shipment IdentifyID (SHIPID) 如何生成?

钜添

56 文章
2 分類
1 页面
GitHub 日记技术
php apache centos macos mysql https shadowsocks mac 微信 ups svn javascript outline accesskey Chrome Extension letsencrypt ssl free certification certbo wildcard renew cloudflare pgsql 归档 binlog isset array_key_exists redmine axure
© 2026 钜添   |   文章 RSS     |  登录
由 Typecho 强力驱动
主題 - NexT
Send message encrypted and private - Msg2
Build your Under Construction Page without hosting - UnderConstruct.IO