duanchuang6978 2013-03-06 22:24
浏览 34
已采纳

具有多个键的多维数组输出到foreach循环

I have a MD Array, which I need to run a function on to return a result. To put it into context, its 5 servers with 1-3 hard drives that gets available remaining space.

$array = array(
"Server 1" => array("C" => "85791338496", "D" => "322119397376"),
"Server 2" => array("C" => "268327448576", "E" => "536733544448", "H" => "274874757120"),
"Server 3" => array("C" => "42947571712", "E" => "214744166400"),
"Server 4" => array("C" => "64317550592", "D" => "150320705536"),
"Server 5" => array("C" => "64317550592")
);

It needs to loop through each server, then each hard drive to return the available space. The function to do that is under control, but the loop based on the above array is where I am stuck.

  • 写回答

1条回答 默认 最新

  • douzhuan1467 2013-03-06 22:28
    关注
    foreach ($array as $server => $disks) {
        print $server .' has the following disks:';
        foreach ($disks as $disk => $avalable_space) {
            print $disk .' has '. $available_space . 'available space';
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路