从PHP数组填充辅助选择框

时间:2018-06-26 15:19:06

标签: php html bootstrap-4

我有一个目前已经硬编码的数组:

$displays = array(
    "Company" => array(
      "Company 1"=>array(
        "Displays"=>array(
          "Room One",
          "Room Two",
          "Room Three",
          ),
        ),
      "Company 2"=>array(
        "Displays"=>array(
          "Room Two",
          "Room Three",
          ),
        ),
      "Company 3"=>array(
        "Displays"=>array(
          "Room One",
          "Room Two",
          ),
        ),
      "Company 4"=>array(
        "Displays"=>array(
          "Room One",
          "Room Two",
          "Room Three"
        ),
      ),
    ),
  );

我目前有第一个选择框,其中显示公司1,2,3和4。但是,我希望仅在选择公司后才显示第二个选择,此时我也希望第二个选择框显示显示仅适用于所选公司的区域

<div class="form-group">
  <label for="companySelect">Select A Location</label>
  <select class="form-control" id="companySelect">
    <?php foreach($displays["Company"] as $area_name => $area_details): ;?>
    <option><?php echo $area_name ?></option>
  </select>

  /*I want the below select to be hidden until a company is selected. Then, I'd like this select to show with the available areas for that company*/

  <label for="areaSelect">Select An Area</label>
  <select class="form-control" id="areaSelect">
    <option><?php echo ${this should be all available Displays for the selected area} ?></option>
    <?php endforeach ?>
  </select>
</div>

0 个答案:

没有答案