$all = 10;
$hit = 6;
$queue = new SplQueue();
$start = 1;
$datas = range($start,$start+$all-1);
var_dump($datas);
foreach ($datas as $data){
$queue->push($data);
}
$index = 1;
while ($queue->count() > 1){
$data_now = $queue->dequeue();
if ($index % $hit == 0){
var_dump($data_now .' is popped');
}else{
$queue->enqueue($data_now);
}
$index++;
}
var_dump($queue->dequeue());
其他方式:
递归/算法 https://www.cnblogs.com/china90/p/7367396.html