public9nf
public9nf

Reputation: 1399

Display 3 array elements per div tag

I have a problem creating a module in joomla. My php skills are restricted. I use foreach to show elements in the template file:

<?php foreach ($filtered_array as $index => $value) { ?>
    <div>show information></>
<?php } ?>

How can I use array_chunk() to group 3 elements into one div and the next 3 into another div?

Upvotes: 0

Views: 98

Answers (1)

Philipp
Philipp

Reputation: 15629

Just use array_chunk as you told and a nested loop.

<?php foreach (array_chunk($filtered_array, 3) as $row): ?>
    <?php foreach ($row as $value): ?>
        <div>show information></div>
    <?php endforeach; ?>
<?php endforeach; ?>

Upvotes: 2

Related Questions