What are some best practices for structuring CSS classes based on PHP logic?

When structuring CSS classes based on PHP logic, it is important to keep the code clean and organized. One best practice is to use conditional statements within the HTML output to dynamically add classes based on PHP variables or conditions. This allows for more flexibility and control over the styling of elements based on the data or logic in the PHP code.

<?php
$color = 'blue';

echo '<div class="';
if ($color === 'blue') {
    echo 'blue ';
}
if ($color === 'red') {
    echo 'red ';
}
echo 'box">This is a colored box</div>';
?>