我有一张比赛日桌子。周五、周六、周日都有比赛。 但我不想在周六的每场比赛中显示周六的日期 4x。 应该是这样的
1.10.
game
2.10.
game
game
game
3.10.
game
game
<?php
foreach ($matches as $match) {
?>
<tr>
<td colspan="5"><?php
$datetime = new DateTime( "now", new DateTimeZone( "Europe/Bucharest" ) );
setlocale(LC_TIME, 'de_DE', 'deu_deu');
$datetime = new DateTime($match["matchDateTime"]);
echo $datetime->format('j.m. | H:i');
?> Uhr</td>
</tr>
<tr>
<td class="icon"><img src="<?php echo $match["team1"]["teamIconUrl"]; ?>" height="30"></td>
<td class="result">
<div class="result2"><?php echo $match["matchResults"][1]["pointsTeam1"]; ?> : <?php echo $match["matchResults"][1]["pointsTeam2"]; ?></div>
</td>
<td class="icon"><img src="<?php echo $match["team2"]["teamIconUrl"]; ?>" height="30"></td>
</tr>
<?php
}
?>
尝试这样的代码(未经测试)或类似的逻辑。将最后一个日期时间存储在变量中并检查它是否已更改:
<?php
function getDatetime($match)
{
$datetime = new DateTime("now", new DateTimeZone("Europe/Bucharest"));
setlocale(LC_TIME, 'de_DE', 'deu_deu');
$datetime = new DateTime($match["matchDateTime"]);
return $datetime->format('j.m. | H:i');
}
$lastDatetime = null;
foreach ($matches as $match) {
$datetime = getDatetime($match);
if($lastDatetime != $datetime) {
$lastDatetime = $datetime;
?>
<tr><td colspan='5'><?=$datetime;?> Uhr</td></tr>
<?php
}
?>
<tr>
<td class="icon"><img src="<?=$match["team1"]["teamIconUrl"]; ?>" height="30"></td>
<td class="result">
<div class="result2"><?=$match["matchResults"][1]["pointsTeam1"]; ?> :
<?=$match["matchResults"][1]["pointsTeam2"]; ?>
</div>
</td>
<td class="icon"><img src="<?=$match["team2"]["teamIconUrl"]; ?>" height="30"></td>
</tr>
<?php
}
?>
对未来的一些提示:
<?=$var; ?>
来代替。<td colspan='5'>
,如果您的中没有更多元素
表比你的问题中的,它不应该是 5,而是
您希望单个单元格跨越的列数。