How can PHP be used to dynamically change the color of text based on certain conditions, such as highlighting specific data in a table?

To dynamically change the color of text based on certain conditions in PHP, you can use inline CSS styles within your HTML output. For example, you can use an if statement to check a condition and then apply a different color style to the text accordingly. This can be particularly useful when highlighting specific data in a table based on certain criteria.

<?php
$data = 10; // Example data to be highlighted

if ($data > 5) {
    echo '<span style="color: red;">' . $data . '</span>';
} else {
    echo '<span style="color: blue;">' . $data . '</span>';
}
?>