I’ve got a list of ID’s coming from a DB table in a particular order. They’ll have a ”groupId’ value.
I need to assign each one a “color” from an array (RGB value). For example my data would be
12
3
45
12
12
3
45
3
45
So for example, so the first one is 12, assign it the first color in my array, next is 3 so gets the second value. When I come back to 12, I want to reuse that one.
My approach has been to pass in the ID to a function, see if it’s in an array. If so return it. If not add it and return the value.
I’m a bit lost however
“`
function colorMap($groupId){
$colorAssignment = array();
if (in_array($colorAssignment, $groupId)){
return $colorAssignment[???]];
} else {
$colorAssignment[] = array($groupId, ??);
}
}