打破PHP数组到3 colums [英] Break PHP array into 3 colums
本文介绍了打破PHP数组到3 colums的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图打破一个PHP数组到3列(已被列,不列),所以它看起来是这样的:
I'm trying to break a PHP array into 3 columns (has to be columns, not rows) so it would look something like this:
Item 1 Item 2 Item 3
Item 4 Item 5 Item 6
Item 7 Item 8 Item 9
Item 10................
我能想到的最好的办法是在主阵列打入3阵列,1为每列虽然我不能制定出最佳的方法来做到这一点 - 更具体的标准,我可以用它来生成3数组。
The best approach I can think of would be to break the main array into 3 arrays, 1 for each column although I can't work out the best approach to do this - more specifically the criteria I could use to generate the 3 arrays.
推荐答案
我会用这样的:
$i = 1
foreach ($array as $value) {
if ($i % 3 === 0) {
echo $value . '<br />';
}
$i++;
}
或HTML表时:
<table>
<tr>
<?php
$i = 0;
foreach ($array as $value) {
if ($i % 3 === 0) {
echo '</tr><tr>';
}
echo "<td>" . $value . "</td>";
$i++;
}
?>
</tr>
<table>
这篇关于打破PHP数组到3 colums的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文