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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里