In PHP, what are some alternative approaches to repeating patterns, such as color codes, without using explicit repetition in regular expressions?

When dealing with repeating patterns in PHP, such as color codes, one alternative approach is to use arrays to store the values and iterate over them to avoid explicit repetition in regular expressions. This can help make the code more concise, easier to maintain, and less error-prone.

<?php
$colorCodes = [
    'red' => '#FF0000',
    'blue' => '#0000FF',
    'green' => '#00FF00'
];

foreach ($colorCodes as $color => $code) {
    echo "The color {$color} has the code {$code} <br>";
}
?>