2 回答
TA贡献1895条经验 获得超3个赞
似乎只有两支球队在比赛,所以只需将代码更改为:
foreach ($item["competitors"] as $teams){
print '
<div class="game-meta game-team">
<img class="game-team__logo game-team__logo-tc" alt="Tawa" src="https://summerseries.nz/wp-content/themes/SS/logos/'; echo $teams['teamCode']; print '.svg">
<div class="game-team__abbrev">'; echo $teams['teamCode']; print'</div>
</div>
<div class="game-meta game-vs">vs</div>';
};
到:
print '
<div class="game-meta game-team">
<img class="game-team__logo game-team__logo-tc" alt="Tawa" src="https://summerseries.nz/wp-content/themes/SS/logos/'; echo $item["competitors"][0]['teamCode']; print '.svg">
<div class="game-team__abbrev">'; echo $item["competitors"][0]['teamCode']; print'</div>
</div>
<div class="game-meta game-vs">vs</div>';
print '
<div class="game-meta game-team">
<img class="game-team__logo game-team__logo-tc" alt="Tawa" src="https://summerseries.nz/wp-content/themes/SS/logos/'; echo $item["competitors"][1]['teamCode']; print '.svg">
<div class="game-team__abbrev">'; echo $item["competitors"][1]['teamCode']; print'</div>
</div>';
如果有超过 2 支球队进行比赛,请告诉我,我会更改解决方案
祝你有美好的一天~
TA贡献2039条经验 获得超7个赞
计算您已经执行了多少次循环,<div>如果不是最后一次迭代,则仅打印“vs”:
$i = 0; // How many teams we've printed so far
foreach ($item["competitors"] as $teams){
print '
<div class="game-meta game-team">
<img class="game-team__logo game-team__logo-tc" alt="Tawa" src="https://summerseries.nz/wp-content/themes/SS/logos/'; echo $teams['teamCode']; print '.svg">
<div class="game-team__abbrev">'; echo $teams['teamCode']; print'</div>
</div>
';
if ( ++$i < sizeof($item["competitors"]) ) {
print '
<div class="game-meta game-vs">vs</div>
';
}
}
- 2 回答
- 0 关注
- 130 浏览
添加回答
举报