What are some best practices for iterating through data in PHP and applying conditional formatting?

When iterating through data in PHP and applying conditional formatting, it is best to use a loop (such as a foreach loop) to iterate through the data and apply conditional statements within the loop to format the data based on certain conditions. This allows you to dynamically apply formatting based on the data being processed.

$data = [10, 20, 30, 40, 50];

foreach ($data as $value) {
    if ($value < 30) {
        echo "<span style='color: red;'>$value</span><br>";
    } else {
        echo "<span style='color: blue;'>$value</span><br>";
    }
}