PHP:根据结果设置表格单元格背景

I'm trying to generate colours based on output of a csv (originally formatted ping).

I can get the values no problem,but the if, ifelse, else doesn't seem to be working.

if($min > 0.499 && $min <= 1) {$tcolor = $yellow;} elseif($min >= 1.0) {$tcolor = $red; } else { $tcolor = $white;}
if($avg > 0.499 && $avg <= 1) {$tcolor = $yellow;} elseif($avg >= 1.0) {$tcolor = $red; } else { $tcolor = $white;}
if($max > 0.499 && $max <= 1) {$tcolor = $yellow;} elseif($max >= 1.0) {$tcolor = $red; } else { $tcolor = $white;}
if($mdev > 0.499 && $mdev <= 1) {$tcolor = $yellow;} elseif($mdev >= 1) {$tcolor = $red; } else { $tcolor = $white;}

echo "<tr><td>$ip</td><td bgcolor=\"$tcolor\">$min<br>$tcolor</td><td bgcolor=\"$tcolor\">$avg<br>$tcolor</td><td bgcolor=\"$tcolor\">$max<br>$tcolor</td><td bgcolor=\"$tcolor\">$mdev</td></tr>";

Edit: As many asked about the colour code already, I have it above the code listed as

$yellow = "#FFFF66";
$red = "#FF0000";
$white = "#FFFFFF";

And the number I see the overlap, but I've also tried with 0.999 with the same result.

It sounds like you got it solved, but you should look at using functions like so, so you don't have to repeat if statements like you did.

<?php

    function setCellColor($value){

        $color = '#FFFFFF';

        if($value >= 0.5 && $value <= 1){
            $color = '#FFFF00';
        } else if($value > 1) {
            $color = '#FF0000';
        }

        return ' style="background: ' . $color . '" ';
    }

    echo '<tr><td>' . $ip . '</td><td ' . setCellColor($min) . '>' . $min . '</td><td ' . setCellColor($avg) . '>' . $avg . '</td><td ' . setCellColor($max) . '>' . $max . '</td><td ' . setCellColor($mdev) . '>' . $mdev . '</td></tr>';

?>

Check this out:

function build_td_with_style($value) {
    switch (true) {
        case $value > 0.5 && $value <= 1 :
            $class = 'yellow';
            break;
        case $value > 1 :
            $class = 'red';
            break;
        default : 
            $class = 'white';
    }

    return "<td class='{$class}'>{$value}</td>";
}

$tds = implode('', array_map("build_td_with_style", [$min, $avg, $max, $mdev]));

echo "<tr><td>{$ip}</td>{$tds}</tr>";

style.css :

   .yellow {
       background-color: yellow;
   }
   .red {
       background-color: red;
   }
   .white {
       background-color: white;
   }