  <?php

error_reporting(-1);
mb_internal_encoding('utf-8');

$total = 7;
$step  = 4;

$citizens  = range(1, $total);
$positions = array_combine($citizens, $citizens);
print_r($positions);

while (count($positions) >= $step) {
    
    for ($i = 1; $i < $step; $i++) {
        $cur = next($positions);
        
        if ($cur === false) {
        	echo "the $i iteration - reached the end. Rewinding...\n";
           $cur = reset($positions);
            echo "now current is ".current($positions)."\n";
            
        }
    }
    echo "deleting $cur. \n";
    unset($positions[$cur]);
    
    if (current($positions) === false) {
        reset($positions);
    }
    
      echo "count will now start from " . current($positions) . "\n";
      echo "The people still in game:\n";
      print_r($positions);
}
echo "Выигрышные места: ";
echo implode(", ", array_values($positions)) . ". \n";
