duande1146 2014-10-23 13:34
浏览 71
已采纳

PHP,在foreach语句中从数组中获取值

I have an array in PHP defined like this:

array(4) {
  [2]=>
  array(35) {
    [64055]=>
    int(1)
    [63682]=>
    int(1)
    [63441]=>
    int(1)
    [63180]=>
    int(1)
    [62867]=>
    int(1)
    [62866]=>
    int(1)
    [62801]=>
    int(1)
    [62425]=>
    int(1)
    [61557]=>
    int(1)
    [61432]=>
    int(1)
    [60777]=>
    int(1)
    [60473]=>
    int(1)
    [60181]=>
    int(1)
    [56466]=>
    int(1)
    [54520]=>
    int(1)
    [54368]=>
    int(1)
    [52155]=>
    int(1)
    [52090]=>
    int(1)
    [51399]=>
    int(1)
    [51081]=>
    int(1)
    [48540]=>
    int(1)
    [45649]=>
    int(1)
    [45099]=>
    int(1)
    [43147]=>
    int(1)
    [39122]=>
    int(1)
    [37309]=>
    int(1)
    [29849]=>
    int(1)
    [28732]=>
    int(1)
    [23916]=>
    int(1)
    [23644]=>
    int(1)
    [23351]=>
    int(1)
    [21351]=>
    int(1)
    [16970]=>
    int(1)
    [16781]=>
    int(1)
    [16763]=>
    int(1)
  }
  [6]=>
  array(1) {
    [63854]=>
    int(1)
  }
  [4]=>
  array(7) {
    [62921]=>
    int(1)
    [58863]=>
    int(1)
    [50981]=>
    int(1)
    [49118]=>
    int(1)
    [36078]=>
    int(1)
    [27718]=>
    int(1)
    [21813]=>
    int(1)
  }
  [21]=>
  array(1) {
    [38328]=>
    int(1)
  }
}

How can I loop through this array to get the digits [2], [6], and [4]? I want to print out those digits. Anyone who can help me with this? I can't figure it out how to do an foreach to do this.

  • 写回答

4条回答 默认 最新

  • duangu6431 2014-10-23 13:39
    关注

    Georges answer si the best but if you wanted a foreach its

    foreach ($array as $key => $value) {
        echo $key;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题