What alternative approaches can be used to dynamically change the background color of a cell in a table without using IF statements in PHP?

Using a switch statement in PHP can be an alternative approach to dynamically change the background color of a cell in a table without using IF statements. Switch statements provide a cleaner and more concise way to handle multiple conditions compared to nested IF statements.

<?php
$color = "red";

switch($color) {
    case "red":
        $bgColor = "background-color: red;";
        break;
    case "blue":
        $bgColor = "background-color: blue;";
        break;
    case "green":
        $bgColor = "background-color: green;";
        break;
    default:
        $bgColor = "background-color: white;";
}

echo "<td style='$bgColor'>Cell Content</td>";
?>