doujiao8649 2018-06-13 14:24
浏览 20
已采纳

为新级别的数组添加额外级别的foreach循环

I've got an additional level added to a multidimensional array and I'm trying to find the best way to incorporate a new foreach loop, or alter current loops, so that my modal body properly adds a new section for each page type.

Basically, My modal should have a header for each company and display(room) and the body should have a section for each page type in that display/room.

What I have so far is good up to the modal header, but now I've commented a new section for where I need a new loop to actually show the page type and expiration.

here's the code so far:

<?php

$displays = array(
"Company" => array(
  "Company One Main"=>array(
    "Displays"=>array(
      "Room One"=>array(
        "Page"=>array(
          "Type"=>"News",
          "Expiration"=>"06/12/2018"),
      ),
      "Room Two"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
      "Room Three"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
    ),
  ),
  "Company One Other"=>array(
    "Displays"=>array(
      "Room Two"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
      "Room Three"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
    ),
  ),
  "Company Two Main"=>array(
    "Displays"=>array(
      "Room One"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
      "Room Two"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
    ),
  ),
  "Company Two Other"=>array(
    "Displays"=>array(
      "Room One"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
      "Room Two"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
      "Room Three"=>array(
        "Page"=>array(
          "Type"=>"Social",
          "Expiration"=>"06/18/2018"),
      ),
    ),
  ),
),
);

?>

<div class="col-lg-4 col-md-12 col-sm-12">
<div class="page-header">
  <h2>Pages Expiring Soon</h2>
</div>
<div class="card" id="expDisplays" style="margin-bottom:20px; padding:10px;">
  <?php foreach($displays["Company"] as $area_name => $area_details): ?>
    <h6><?php echo $area_name ?><a href="#" data-toggle="modal" data-target="#expiringDisplays">Edit</a></h6>
    <!-- Modal -->
    <div class="modal fade" id="expiringDisplays" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
          <?php foreach($area_details["Displays"] as $d=>$v): ?>
          <h5 class="modal-title" id="modalLabel"><?php echo  $area_name . " - " . $d?></h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
          <!-- END MODAL HEADER -->
          </div>

          <!--Everything works to this point, I need a new foreach to show page types and expirations-->
          <div class="modal-body">
            <!--Need new foreach to get page types and their corresponding expiration-->
            <br>
            <h6><?php echo $v['Type'] ?></h6>
            <h6>Date/Time Expiring: <?php echo $v["Expiration"] ?></h6>
            <h6>Set New Expiration: <input data-date-format="mm/dd/yyyy" id="datepicker" name="datepicker"></h6>
            <a href="#" style="float:left;">View Display</a>
            <br>
            <hr>
            <?php endforeach; ?>
            <!-- END MODAL BODY -->
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
            <!-- END MODAL FOOTER -->
          </div>
          <!-- END MODAL CONTENT -->
        </div>
        <!-- END MODAL DIALOGUE -->
    </div>
    <!-- END MODAL -->
  </div>
  <?php //endforeach; ?>
  <?php endforeach; ?>
</div>

  • 写回答

1条回答 默认 最新

  • doudun2565 2018-06-13 14:48
    关注

    You need to put a new foreach loop inside the modal-body. Try this:

    <div class="modal-body">
               <?php foreach($v as $k=>$n){ ?>
                <!--Need new foreach to get page types and their corresponding expiration-->
                <br>
                <h6><?php  echo $n['Type']; ?></h6>
                <h6>Date/Time Expiring: <?php echo $n["Expiration"] ?></h6>
                <h6>Set New Expiration: <input data-date-format="mm/dd/yyyy" id="datepicker" name="datepicker"></h6>
                <a href="#" style="float:left;">View Display</a>
                <br>
                <hr>
                  <?php } endforeach; ?>
                <!-- END MODAL BODY -->
              </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度