I'm wondering if there is a function built into PHP that I could leverage to loop through an array, and reset to the beginning to continue to loop again.
The use of this would be an array of colors for an SVG that is created with a PHP function. I think my max case would be X but I want to make sure if I have more than X I restart with the color codes.
Below is the code I have that works, but wondering if there is a built in function to do this.
$color_array = array( 1 => '#00cc00', 2=> '#B45F04', 3=> '#0101DF', 4=> '#B40486', 5=> 'F1F105', 6=>'F10505');
$num_color_array = count($color_array); //get number of elements
foreach(loop through array 1){ //psuedo code
$array_color_index = 1;
foreach(loop throguh array 2){ //psuedo code
if($array_color_index > $num_color_array){
$array_color_index = 1; //if > num elements reset
}
$color_fill = $color_array[$array_color_index]; //pull the color code
fill:'.$color_fill.' //use the color code here...simplified for example...
$array_color_index++; //increment index
}
}
whileloop