I have some switch cases in PHP where I’d like to count some types of values once.
I will show a screenshot to understand what I mean:
So, you can see the values into the red circle. I’d like to count once that value. This is an example:
(if there is “going +3”) Count +3 once;
(if there is “going +1”) Count +1 once;
(if there isn’t nothing like before) Count -2 once;
and so on with the others value: course, distance, class etc etc
This is an example of my code:
switch(true)
{
case ($row['course'] == $courses and $row['pos'] == "1"):
echo "<td style='background-color:#00FF00'><b><font color='red'><u> Course: +2;</u> </font></b></td>";
$showcourse1 = "2";
break;
case ($row['course'] == $courses and $row['pos'] == "2"):
echo "<td style='background-color:#00FF00'><b><font color='purple'><u> Course: +1;</u> </font></b></td>";
$showcourse2 = "1";
break;
default:
echo "<td> Course: -2; </td>";
$showcourse3 = "-2";
break;
}
switch(true)
{
case ($row['dist'] == $distances and $row['pos'] == "1"):
echo "<td style='background-color:#00FF00'><b><font color='brown'><u> Distance: +3;</u> </font></b></td>";
$showdistance1 = "3";
break;
case ($row['dist'] == $distances and $row['pos'] == "2"):
echo "<td style='background-color:#00FF00'><b><font color='turquoise'><u> Distance: +1;</u> </font></b></td>";
$showdistance2 = "1";
break;
default:
echo "<td> Distance: -2; </td>";
$showdistance3 = "-2";
break;
}
Sorry if my explanation is not so clear, but I don’t know how to explain it better
Thanks for your help