What are some best practices for efficiently handling color changes in PHP loops?

When handling color changes in PHP loops, it is important to efficiently manage the logic for changing colors without sacrificing performance. One common approach is to use a conditional statement within the loop to alternate between different colors based on the iteration count.

$colors = array('red', 'blue', 'green');
$colorIndex = 0;

for ($i = 0; $i < 10; $i++) {
    $currentColor = $colors[$colorIndex];
    
    // Output code using $currentColor
    
    $colorIndex = ($colorIndex + 1) % count($colors);
}