What are the best practices for loading a stylesheet in PHP based on a condition?

When loading a stylesheet in PHP based on a condition, it is best practice to check the condition first and then include the stylesheet if the condition is met. This can help optimize the loading of resources and ensure that only necessary styles are included.

<?php
if ($condition) {
    echo '<link rel="stylesheet" type="text/css" href="styles.css">';
}
?>