What are some best practices for dynamically assigning CSS classes in PHP?

When dynamically assigning CSS classes in PHP, it is important to keep the code clean and maintainable. One best practice is to separate the logic for determining the CSS class into a separate function, making it easier to manage and update in the future. Additionally, using conditional statements or arrays to map specific conditions to corresponding CSS classes can help streamline the process and make the code more readable.

<?php

function getCssClass($condition) {
    if ($condition) {
        return 'success';
    } else {
        return 'error';
    }
}

$someCondition = true;
$cssClass = getCssClass($someCondition);

echo '<div class="' . $cssClass . '">Dynamic CSS Class</div>';

?>