<?php

error_reporting(-1);

$total = 30; // Всего в классе 30 человек
$skip = 5; // Считалка содержит 5 слогов

$arrayParticipants = range(1,$total); // Участники считалки от 1 до $total. Массив от 0 до $total-1
$numberWhoOutNext = $skip-1; // Кто выбывает первым

while(count($arrayParticipants)>=$skip)  // Считаем пока участников больше чем слогов
{
    $length = count($arrayParticipants)-1; // Сколько осталось участников

    for ($i = $numberWhoOutNext; $i <= $length; $i = $i + $skip)
    {
        unset($arrayParticipants[$i]);
    }
    $numberWhoOutNext = $i - $length - 1; // Кто выбывает следующим
    sort($arrayParticipants); // Смыкаем порочный круг
}

echo "Выигрышные места: ".implode(", ",$arrayParticipants)."\n";



