You can do it directly in PHP
Declare an array that contains color codes and use the array when creating the <div> dynamically. See the code below for an example.
<?php $color= array("#341014", "#BE6353", "#2F2E3B","#20222B","#BB644C","#F8834E","#E4B9AC"); $i=0; while($event!=$nextEvent){ echo"<div id='sportType' style='background-color:".$color[i].";'>";
You can simply specify any number of colors in the array, and it will apply colors accordingly, even if a large number of <div> , for example, for example, if you want to create 100 divs, you can simply add 100 or more than 100 color codes in your array, and these colors will be used in the while loop.
source share