2 回答
TA贡献1887条经验 获得超5个赞
我会用array_chunk():
foreach (array_chunk($get_plans, 3) as $chunk) {
echo '<div class="flex">';
foreach ($chunk as $plan) {
echo '<div class="flex-33">';
echo 'ID: ' . $plan['id'] . '; ' . 'Name: ' . $plan['name'];
echo '</div>';
}
echo '</div>';
}
结果将是这样的:
<div class="flex">
<div class="flex-33">ID: ID1; Name: Name1</div>
<div class="flex-33">ID: ID2; Name: Name2</div>
<div class="flex-33">ID: ID3; Name: Name3</div>
</div>
<div class="flex">
<div class="flex-33">ID: ID4; Name: Name4</div>
<div class="flex-33">ID: ID5; Name: Name5</div>
<div class="flex-33">ID: ID6; Name: Name6</div>
</div>
<div class="flex">
<div class="flex-33">ID: ID7; Name: Name7</div>
</div>
- 2 回答
- 0 关注
- 124 浏览
添加回答
举报