Output Array Contents as HTML

I have a PHP array (take a look here) and I'm trying to loop over it and output the data as HTML list. The fields I am trying to show are only content and createdAt.

Here is the HTML template I have in mind, I just need to output the data in a similar way.

<div class="pages">
  <div data-page="projects" class="page no-toolbar no-navbar">
    <div class="page-content">
      <div class="navbarpages">
        <div class="navbar_home_link">
          <a href="index.html">
            <img src="images/icons/white/home.png" alt="" title="" />
          </a>
        </div>
        <div class="navbar_page_center">ALLE ZITATE</div>
        <div class="menu_open_icon_white">
          <a href="#" class="open-panel">
            <img src="images/menu_open.png" alt="" title="" />
          </a>
        </div>
      </div>
      <div id="pages_maincontent">
        <h2 class="page_subtitle">Alle Zitate</h2>
        <ul class="features_list_detailed">
          <li class="swipeout">
            <div class="swipeout-content item-content">
              <div class="post_entry">
                <div class="post_thumb">
                  <div style="font-size: 30px; font-style: bold;">24</div>
                  <div style="text-transform: uppercase; font-style: bold;">January</div>
                </div>
                <div class="post_details">
                  <p>
                    <strong>
                    "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium"
                    </strong>
                  </p>
                </div>
              </div>
            </div>
          </li>
          <li class="swipeout">
            <div class="swipeout-content item-content">
              <div class="post_entry">
                <div class="post_thumb">
                  <div style="font-size: 30px; font-style: bold;">24</div>
                  <div style="text-transform: uppercase; font-style: bold;">January</div>
                </div>
                <div class="post_details">
                  <p>
                    <strong>
                    "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium"
                    </strong>
                  </p>
                </div>
              </div>
            </div>
          </li>
        </ul>

Could someone please help? Thanks in advance.

1 answer

  • answered 2018-01-14 02:47 Innervisions

    Here is a really basic example

      <?php 
            $list = array("value1","value2","value3","value4");
    
            foreach ($list as $list_values) {
                ?>
                <li><?php echo $list_values; ?></li>
                <?php
            }
        ?>
    

    You just foreach inside your array and than put the html inside it and it will loop your html X amount of times

  • Take array of names from web-service and display in view
       var url = "../webservices/dependantusers/subAccountsDetails?individualId=" + self.selectedUser.id;
                $http.get(url).then(function (result) {
    
                //  alert(result.data.data[1].firstName);
                self.dependents = result.data;
    
                // console.log(self.dependents.data.length);
                for (var index = 0; index < self.dependents.data.length; index++) {
                    // alert(self.dependents.data[index].firstName +' '+self.dependents.data[index].lastName);
                    self.dependents[index + 1] = self.dependents.data[index];
                }
    

    I'm calling a web service which is returning me some data. I have to get the first names and display it in a list. I have declared dependents as an array on the top.

    Any idea about where I'm going wrong ?