I
I
Ivan2020-04-24 00:59:11
PHP
Ivan, 2020-04-24 00:59:11

How to split foreach output into html blocks?

I display content in the site template in the amount of 10 news. In the template, the content is divided into blocks, the code is:

<div class="col-md-4">
          <article class="card mb-4">
            <header class="card-header">
              <div class="card-meta">
                <a href="#"><time class="timeago" datetime="2019-07-16 20:00">16 july 2019</time></a> in <a href="page-category.html">Work</a>
              </div>
              <a href="post-image.html">
                <h4 class="card-title">How can we, how can we sing about ourselves?</h4>
              </a>
            </header>
            <a href="post-image.html">
              <img class="card-img" src="img/articles/3.jpg" alt="" />
            </a>
            <div class="card-body">
              <p class="card-text">Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. </p>
            </div>
          </article><!-- /.card -->

          <article class="card mb-4">
            <header class="card-header">
              <div class="card-meta">
                <a href="#"><time class="timeago" datetime="2019-10-15 20:00">15 october 2019</time></a> in <a href="page-category.html">Lifestyle</a>
              </div>
              <a href="post-image.html">
                <h4 class="card-title">The king is made of paper</h4>
              </a>
            </header>
            <a href="post-image.html">
              <img class="card-img" src="img/articles/20.jpg" alt="" />
            </a>
            <div class="card-body">
              <p class="card-text">Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. </p>
            </div>
          </article><!-- /.card -->
        </div>


How to <div class="col-md-4">output two by two <article class="card mb-4">

I output it like this:

$c = 1;

foreach($obj['itemListData'] as $key=>$val){ 

$id = $val['itemInfos']['id'];
$text = $val['itemInfos']['text'];

.. . шаблон ...

if ($c == 10) break;

$c++;

}


Confused :( Help please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-04-24
@9StarRu

array_chunk, then two foreach, one nested inside the other
outputs col-md-4, inner - articles

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question