What are some best practices for creating and displaying color tables in PHP?

When creating and displaying color tables in PHP, it is important to organize the colors in a visually appealing and easy-to-read format. One best practice is to use HTML tables to display the colors in rows and columns, with each cell representing a color. Additionally, it is helpful to provide labels or tooltips for each color to indicate its name or value.

<?php
// Define an array of colors
$colors = array(
    "Red" => "#FF0000",
    "Green" => "#00FF00",
    "Blue" => "#0000FF",
    "Yellow" => "#FFFF00",
    "Purple" => "#800080"
);

// Display the color table using HTML
echo "<table>";
foreach ($colors as $name => $value) {
    echo "<tr>";
    echo "<td style='background-color: $value; width: 50px; height: 50px;'></td>";
    echo "<td>$name</td>";
    echo "<td>$value</td>";
    echo "</tr>";
}
echo "</table>";
?>