dongmei8209 2015-11-24 05:31
浏览 48
已采纳

PHP如何回显3-Dim数组

After searching for an answer in this forum I found only related questions but under other context that would not apply to my case. Here's my problem:

I have a 3-dim array defined in a function like this:

$m_Array[h][$family][$iterator]

the values for

$family range from 6-10;

$iterator from 0-3 but has duplicates (0,1,2,3,1),

and the  $m_Array results in values (25,26,30,31,33).

I am unable to echo the result using those indices to get these results once returned from the function. NOTE: I was able to echo when I had 2-dim $m_Array[h][$iterator] but could not use it because the last value for the iterator would replace the second in the array. Since I was able to echo the 2-dim, this is not a question on getting the return from the function or iterate over the indices. Thanks.

  • 写回答

3条回答 默认 最新

  • dongshan1396 2015-11-24 05:47
    关注

    as others mentioned, you can use var_dump() or print_r(). If you need to access each item then you're going to need nested loops.

    foreach($m_Array as $i => $h)
    {
         //echo $i, $key for h
         foreach($h as $j => $family)
         {
              //echo $j, key for family
              foreach($family as $k => $iterator)
              {
                    echo $iterator;
              }
         }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看