I’m trying to compare two numbers, and add an HTML class to the large one- in this case statistics for a video game. Now I could do $player1[stat]-$player2[stat] and if the result is negative, player2 had a large value or just do normal greater than or less than logic. But, the thing is, I have about 20 different statistics I have to compare and add the class.
What would be the easiest way of making the larger value bold?
I was going to try case switches but that seems tedious. 20 different if-statements also seemed unnecessary.
Thanks!
Edit: Just to be clearer, I need to echo the values as well, but have the largest bolded
$player1[kills] = 55;
$player2[kills] = 40;
$player1[deaths] = 15;
$player2[deaths] = 10;
The desired result:
<table>
<tr>
<th>Statistic</th>
<th>Player 1</th>
<th>Player 2</th>
</tr>
<tr>
<th>Kills</th>
<th><strong>40Player 2</th>
</tr>
<tr>
<th>Deaths</th>
<th>15</th>
<th><strong>10</strong></th>
</tr>
</table>
Another thing- less deaths is better, so is there a way to some how chose the smaller one for that instance?
Retrieve the largest value from each group with something like:
On output:
You can use a ternary operator to shorten this as well:
By the way, please put quotes around your array keys. Although PHP parses them correctly (by assuming you meant to use strings instead of constants), it is issuing a notice for each time you do it even if those notices are just piling up in log files.