What are some best practices for using arrays in PHP to assign colors to user groups?

When assigning colors to user groups in PHP using arrays, it is best to create an associative array where the keys represent the user groups and the values represent the corresponding colors. This allows for easy retrieval of colors based on the user group. Additionally, using predefined color constants or hexadecimal color codes can help maintain consistency and readability in the code.

// Define an associative array mapping user groups to colors
$userColors = [
    'admin' => '#FF0000',
    'moderator' => '#00FF00',
    'user' => '#0000FF'
];

// Retrieve color for a specific user group
$userGroup = 'admin';
$color = $userColors[$userGroup];

echo "Color for $userGroup group is: $color";