foreach迭代以匹配数组内容

时间:2019-01-23 15:48:39

标签: php foreach

我有一个数组,该数组接受与指定键匹配的值,并在表中回显结果。然后,我要具有一种功能,当您单击这些项目中的每一个时,它会弹出一个包含更多项目详细信息的模式。

我从包含键/值对的源中获取了JSON。我用与给定键匹配的值填充了数组,并打印了这些内容。我有打开模态的代码。现在,我需要使用模式来提取所需的详细信息,所以我重复了上述步骤,用[DESCRIPTION]键中的值填充数组。

  $subjectList = array();
  foreach($responseResult as $subject) {       // Loop over JSON and fill an  
    $subjectList[] = $subject['subject'];      // array with subject.
  }
  $modalContent = array();
  foreach($responseResult as $arrayItem) {     // Loop over JSON and fill an
    $modalContent[] = $arrayItem['summary'];   // array with details.
  }
  $submit = array_slice($subjectList, 0, 50);
  foreach($submit as $use) {
    echo "<tr><th scope='row'><span class='glyphicon glyphicon-list-alt'></span></th><td><a href='#' style='color:#fff;text-transform:uppercase;' data-toggle='modal' data-target='#myModal'>{$use}</a>";
  }


    <div class='modal fade' id='myModal' tabindex='1' role='dialog' aria-labelledby='myModalLabel'>
      <div class='modal-dialog' role='document'>
        <div class='modal-content'>
          <div class='modal-header'>
            <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
            <h4 class='modal-title' id='myModalLabel'>Juno | Ticket Details</h4>
        </div>
        <div class='modal-body'>
         <?php
           echo $modalItem;
         ?>
        </div>
        <div class='modal-footer'>
          <button type='button' class='btn btn-default btn-wman' data-dismiss='modal'>Close</button>
        </div>
      </div>
     </div>
    </div>

我需要在数组索引之间进行某种匹配,因此,当用户单击给定的[SUBJECT]时,他们将获得该主题的相应[DESCRIPTION]。我有一个模糊的想法,也许使用array_keys()或if语句?

我拥有的代码打开模态并将相同的[DESCRIPTION]放入每个[SUBJECT]。我感觉我好亲近!

2 个答案:

答案 0 :(得分:0)

也许这就是您想要的?

$subjectList = [];
$modalContent = [];

foreach($responseResult as $index => $item) {  // Loop over JSON and fill an  
    $subjectList[$index] = $item['subject'];   // array with subject.
    $modalContent[$index] = $item['summary'];  // array with details.
}

答案 1 :(得分:0)

您可能想要这样的东西:

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.largeTitleDisplayMode = .never
    }

}