用php比较两个值,突出显示最高值

时间:2015-09-01 10:18:51

标签: php html wordpress

我试图通过比较两个团队的得分来突出显示篮球比赛中的胜利者,并通过在HTML元素中添加类“赢家”来突出显示获胜者(最高得分)团队:

<ul class="game-result">
   <li class="winner"><span>Team 1</span><?php echo $team1_points; ?></li>
   <li class=""><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>

我正在使用wordpress和php,任何帮助都将不胜感激!

由于

3 个答案:

答案 0 :(得分:1)

喜欢这样

<ul class="game-result">
<li <?php echo (($team1_points>$team2_points)?'class="winner"':''); ?>><span>Team 1</span><?php echo $team1_points; ?></li>
<li <?php echo (($team2_points>$team1_points)?'class="winner"':''); ?>><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>

答案 1 :(得分:0)

<ul class="game-result">
  <li <?=($team1_points > $team2_points ? "class='winner'" : "")?> ><span>Team 1</span><?php echo $team1_points; ?></li>
</ul>

答案 2 :(得分:0)

<ul class="game-result">
     <li <?php echo (($team1_points>$team2_points)?'class="winner"':'class=""'); ?>><span>Team 1</span><?php echo $team1_points; ?></li>
     <li <?php echo (($team2_points>$team1_points)?'class="winner"':'class=""'); ?>><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>

即使Flyer的回答是正确的,但是当你在问题描述中发布时,这个代码会使你的代码看起来完全