
<?php
function king($n, $m)
{
// 生成数组
$monkey = range(1, $n);
$i = 0;
while (count($monkey) > 1) {
$i += 1; // 从第一个开始
// 将第一个人出环
$head = array_shift($monkey);
if ($i % $m != 0) {
// 将第一个人放到尾部
array_push($monkey, $head);
} else {
// 这个人出环了
//echo $head . '<br>';
}
}
return $monkey[0];
}
echo king(10, 7);
</div>