3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Task { function Task($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); } } ?>
Output for 7.0.0 - 7.2.0
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Task has a deprecated constructor in /in/kPEGu on line 2 task 1 position 2 task 2 position 12 task 3 position 22 task 4 position 32 task 5 position 42 task 6 position 52 task 7 position 62 task 8 position 72 task 9 position 82 task 10 position 92 task 1 position 3 task 2 position 13 task 3 position 23 task 4 position 33 task 5 position 43 task 6 position 53 task 7 position 63 task 8 position 73 task 9 position 83 task 10 position 93 task 1 position 4 task 2 position 14 task 3 position 24 task 4 position 34 task 5 position 44 task 6 position 54 task 7 position 64 task 8 position 74 task 9 position 84 task 10 position 94 task 1 position 5 task 2 position 15 task 3 position 25 task 4 position 35 task 5 position 45 task 6 position 55 task 7 position 65 task 8 position 75 task 9 position 85 task 10 position 95 task 1 position 6 task 2 position 16 task 3 position 26 task 4 position 36 task 5 position 46 task 6 position 56 task 7 position 66 task 8 position 76 task 9 position 86 task 10 position 96 task 1 position 7 task 2 position 17 task 3 position 27 task 4 position 37 task 5 position 47 task 6 position 57 task 7 position 67 task 8 position 77 task 9 position 87 task 10 position 97 task 1 position 8 task 2 position 18 task 3 position 28 task 4 position 38 task 5 position 48 task 6 position 58 task 7 position 68 task 8 position 78 task 9 position 88 task 10 position 98 task 1 position 9 task 2 position 19 task 3 position 29 task 4 position 39 task 5 position 49 task 6 position 59 task 7 position 69 task 8 position 79 task 9 position 89 task 10 position 99 task 1 position 10 task 2 position 20 task 3 position 30 task 4 position 40 task 5 position 50 task 6 position 60 task 7 position 70 task 8 position 80 task 9 position 90 task 10 position 100 task 1 complete task 2 complete task 3 complete task 4 complete task 5 complete task 6 complete task 7 complete task 8 complete task 9 complete task 10 complete
Output for 5.3.19 - 5.6.28
task 1 position 2 task 2 position 12 task 3 position 22 task 4 position 32 task 5 position 42 task 6 position 52 task 7 position 62 task 8 position 72 task 9 position 82 task 10 position 92 task 1 position 3 task 2 position 13 task 3 position 23 task 4 position 33 task 5 position 43 task 6 position 53 task 7 position 63 task 8 position 73 task 9 position 83 task 10 position 93 task 1 position 4 task 2 position 14 task 3 position 24 task 4 position 34 task 5 position 44 task 6 position 54 task 7 position 64 task 8 position 74 task 9 position 84 task 10 position 94 task 1 position 5 task 2 position 15 task 3 position 25 task 4 position 35 task 5 position 45 task 6 position 55 task 7 position 65 task 8 position 75 task 9 position 85 task 10 position 95 task 1 position 6 task 2 position 16 task 3 position 26 task 4 position 36 task 5 position 46 task 6 position 56 task 7 position 66 task 8 position 76 task 9 position 86 task 10 position 96 task 1 position 7 task 2 position 17 task 3 position 27 task 4 position 37 task 5 position 47 task 6 position 57 task 7 position 67 task 8 position 77 task 9 position 87 task 10 position 97 task 1 position 8 task 2 position 18 task 3 position 28 task 4 position 38 task 5 position 48 task 6 position 58 task 7 position 68 task 8 position 78 task 9 position 88 task 10 position 98 task 1 position 9 task 2 position 19 task 3 position 29 task 4 position 39 task 5 position 49 task 6 position 59 task 7 position 69 task 8 position 79 task 9 position 89 task 10 position 99 task 1 position 10 task 2 position 20 task 3 position 30 task 4 position 40 task 5 position 50 task 6 position 60 task 7 position 70 task 8 position 80 task 9 position 90 task 10 position 100 task 1 complete task 2 complete task 3 complete task 4 complete task 5 complete task 6 complete task 7 complete task 8 complete task 9 complete task 10 complete