在 Foreach 语句中的 X 个结果后换行 (PHP)
Doing a line break after X amount of results in a Foreach statement (PHP)
我有一个 foreach 语句 returns 说出 25 个名字
foreach($player as $item) {
echo $player[$count++];
}
我如何做到在 X 数量之后,比方说 10 个名字,它会换行?完整的代码以 i 为例,所以在第 10 个头像之后,第 11 个将在换行符/
之后开始
foreach($player as $item) {
echo "<td align='center'><img src='" . strtr ( $avatar[$count_avatar++], array ("avatar:" => "", ',' => '' )) . "'><br><font>" . strtr ( $player[$count++], array ("name:" => "", ',' => '' )) . "</font></td><td class='character_spacer'></td>";
}
<?php
$count = 0;
$row_count = 0;
foreach($player as $item)
{
$row_count++;
if ($row_count == 10)
{
$row_count = 0;
echo '<br />'; // It will not work within tr or td you have to add margins here according to your need.
}
$count++;
}
?>
我有一个 foreach 语句 returns 说出 25 个名字
foreach($player as $item) {
echo $player[$count++];
}
我如何做到在 X 数量之后,比方说 10 个名字,它会换行?完整的代码以 i 为例,所以在第 10 个头像之后,第 11 个将在换行符/
foreach($player as $item) {
echo "<td align='center'><img src='" . strtr ( $avatar[$count_avatar++], array ("avatar:" => "", ',' => '' )) . "'><br><font>" . strtr ( $player[$count++], array ("name:" => "", ',' => '' )) . "</font></td><td class='character_spacer'></td>";
}
<?php
$count = 0;
$row_count = 0;
foreach($player as $item)
{
$row_count++;
if ($row_count == 10)
{
$row_count = 0;
echo '<br />'; // It will not work within tr or td you have to add margins here according to your need.
}
$count++;
}
?>