Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为新级别的数组添加额外级别的foreach循环_Php_Arrays_Foreach - Fatal编程技术网

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

Php 为新级别的数组添加额外级别的foreach循环,php,arrays,foreach,Php,Arrays,Foreach,我已经在多维数组中添加了一个额外的级别,我正在试图找到最好的方法来合并一个新的foreach循环,或者改变当前的循环,这样我的模态体就可以为每种页面类型正确地添加一个新的节 基本上,我的模式应该为每个公司和显示(房间)都有一个标题,主体应该为该显示/房间中的每个页面类型都有一个部分 到目前为止,我所做的一切都很好,但现在我已经对一个新的部分进行了注释,我需要一个新的循环来实际显示页面类型和过期时间 以下是迄今为止的代码: <?php $displays = array( "Company

我已经在多维数组中添加了一个额外的级别,我正在试图找到最好的方法来合并一个新的foreach循环,或者改变当前的循环,这样我的模态体就可以为每种页面类型正确地添加一个新的节

基本上,我的模式应该为每个公司和显示(房间)都有一个标题,主体应该为该显示/房间中的每个页面类型都有一个部分

到目前为止,我所做的一切都很好,但现在我已经对一个新的部分进行了注释,我需要一个新的循环来实际显示页面类型和过期时间

以下是迄今为止的代码:

<?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>

即将过期的网页
&时代;

到期日期/时间: 设置新过期日期:

关 保存更改

您需要在模态体中放置一个新的foreach循环。试试这个:

<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>


到期日期/时间: 设置新过期日期:


非常感谢!我不确定我是否应该再做一次foreach或重组,但这一切都很好。