title: Dynamically load array of objects to view them in a modal
body: <p>A PHP function loops through an array of objects and lists down their titles. I have a link that opens a modal. How can I dynamically load the modal header and body with regard to the object $r from the $results when I press details?</p>
  <pre><code>&lt;?php
  foreach ($results as $r) {
  ?&gt;
  
      &lt;div class=&quot;row justify-content-center&quot;&gt;
          &lt;div class=&quot;alert alert-success&quot;&gt;
              &lt;strong&gt;
                  &lt;?php echo $r['_source']['title']; ?&gt;&lt;/strong&gt; &lt;span id=&quot;showSearchTerm&quot;&gt;&lt;/span&gt;&lt;/br&gt;
              &lt;a data-target=&quot;#myModal&quot; data-toggle=&quot;modal&quot; class=&quot;MainNavText&quot; id=&quot;MainNavHelp&quot; href=&quot;#myModal&quot;&gt;Details&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;!-- Modal --&gt;
      &lt;div id=&quot;myModal&quot; class=&quot;modal fade&quot; role=&quot;dialog&quot;&gt;
          &lt;div class=&quot;modal-dialog&quot;&gt;
  
              &lt;!-- Modal content--&gt;
              &lt;div class=&quot;modal-content&quot;&gt;
                  &lt;div class=&quot;modal-header&quot;&gt;
                      &lt;!-- &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot;&gt;&amp;times;&lt;/button&gt; --&gt;
                      &lt;h2 class=&quot;modal-title&quot;&gt;
                          &lt;?php echo $r['_source']['title']; ?&gt;
                      &lt;/h2&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;modal-body&quot;&gt;
                      &lt;p&gt;
                          &lt;?php echo $r['_source']['body']; ?&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;?php echo $r['_source']['path']['real']; ?&gt;
                      &lt;/p&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;modal-footer&quot;&gt;
                      &lt;button type=&quot;button&quot; class=&quot;btn btn-default&quot; data-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;?php
  
  }
  </code></pre>