3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Task { function __construct($id, $start, $end) { $this->id = $id; $this->start = $start; $this->end = $end; $this->pos = $this->start; } function execute() { if ($this->pos < $this->end) { return $this->pos++; } else return false; } } $range = range(1, 100); $ranges = array_chunk($range, 10); $tasks = array(); while (count($ranges)) { $range = array_shift($ranges); $tasks[] = new Task( count($tasks) + 1, array_shift($range), array_pop($range)); } while (count($tasks)) { foreach ($tasks as $id => $task) { if ($task->execute() === false) { printf("task %d complete\n", $task->id); unset($tasks[$id]); } else printf("task %d position %d\n", $task->id, $task->pos); } } ?>

preferences:
78 ms | 408 KiB | 5 Q