Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understood your question correctly, you would need some code like the following:</p> <pre><code>// check how many items will remain in the final row (if the row is not filled with 3 items) $remainder = $total_items % 3; for ($i = 0; $i &lt; $total_items; $i++) { if($remainder &gt; 0 &amp;&amp; $i &gt;= $total_items - $remainder) { // executed for items in the last row, if the number of items in that row is less than 3 (not a complete row) } else { // executed for items that are in 3 column rows only } } </code></pre> <p>Here is a complete example of how something like this would work. Create a new php file with the following code and see the output.</p> <pre><code>// add some random data to an array $data = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven'); $total_items = count($data); // check how many items will remain in the final row (if the row is not filled with 3 items) $remainder = $total_items % 3; // loop through all the items for ($current_item = 0; $current_item &lt; $total_items; $current_item++) { // check to see if the item is one of the items that are in the row that doesn't have 3 items if($remainder &gt; 0 &amp;&amp; $current_item &gt;= $total_items - $remainder) { echo $data[$current_item] . " - item in last row, when row is not complete&lt;br /&gt;"; // code for regular items - the ones that are in the } else { echo $data[$current_item] . " - item in filled row&lt;br /&gt;"; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload