= count($cups)) { $current_index = 0; } } // moves done, now count from 1 $index_1 = array_search(1, $cups, true); $final_labels = ''; $current_index = $index_1 + 1; for ($i = 1, $l = count($cups); $i < $l; $i++) { if ($current_index >= $l) { $current_index = 0; } $final_labels .= $cups[$current_index]; $current_index++; } echo $final_labels;