dsiuy42084 2011-08-25 07:52
浏览 50
已采纳

array_key_exists表示数组中的复合键

How do I check to see if a compound key exists with array_key_exists such as

$myarr['ind1']['ind2']

Would like to see if the key ['ind1']['ind2'] exists in $myarr.

I googled this and looked at some similar answers but couldn't find anything.

  • 写回答

2条回答 默认 最新

  • dqmq0654 2011-08-25 08:14
    关注

    You can make use of issetDocs to check for an array member that not equals NULL, which is the case for a compound array and safe to assume in your case:

    if (isset($myarr['ind1']) && array_key_exists('ind2', $myarr['ind1'])
    {
       ...
    }
    

    If $myarr['ind2'] potentially never equals to NULL you can do the following, which might show better what you're trying to check:

    if (isset($myarr['ind1']['ind2']))
    {
       ...
    }
    

    This checks the compound key does exists and is not NULL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥188 需要修改一个工具,懂得汇编的人来。