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 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题