3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IncrementIterator implements Iterator { protected $start; protected $end; protected $current; public function __construct($start, $end) { $this->start = $start; $this->end = $end; } public function rewind() { $this->current = $this->start; } public function valid() { return $this->current <= $this->end; } public function key() { return $this->current; } public function current() { return $this->current; } public function next() { $this->current++; } } class NestedIterator implements Iterator { protected $iterators = array(); protected $lastIndex = -1; protected $iteration = 0; public function addIterator(Iterator $it) { $this->iterators[] = $it; $this->lastIndex++; } public function rewind() { foreach ($this->iterators as $it) { $it->rewind(); } $this->iteration = 0; } public function valid() { return $this->lastIndex >= 0 && $this->iterators[0]->valid(); } public function key() { return $this->iteration; } public function current() { $return = array(); foreach ($this->iterators as $it) { $return[] = $it->current(); } return $return; } public function next() { $this->iteration++; for ($i = $this->lastIndex; $i >= 0; $i--) { $this->iterators[$i]->next(); if ($this->iterators[$i]->valid()) { $this->iteration++; for ($j = $i + 1; $j <= $this->lastIndex; $j++) { $this->iterators[$j]->rewind(); } } } } } $nestedIterator = new NestedIterator(); $nestedIterator->addIterator(new IncrementIterator(0, 26)); $nestedIterator->addIterator(new IncrementIterator(0, 26)); $nestedIterator->addIterator(new IncrementIterator(0, 26)); $nestedIterator->addIterator(new IncrementIterator(0, 26)); foreach ($nestedIterator as $key => $current) { list($a, $b, $c, $d) = $current; echo "[$key] => $a, $b, $c, $d\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of IncrementIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 24 Deprecated: Return type of IncrementIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 28 Deprecated: Return type of IncrementIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 20 Deprecated: Return type of IncrementIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 16 Deprecated: Return type of IncrementIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 12 Deprecated: Return type of NestedIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 59 Deprecated: Return type of NestedIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 69 Deprecated: Return type of NestedIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 55 Deprecated: Return type of NestedIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 51 Deprecated: Return type of NestedIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/f5TIk on line 43 [0] => 0, 0, 0, 0 [5] => 1, 0, 0, 0 [10] => 2, 0, 0, 0 [15] => 3, 0, 0, 0 [20] => 4, 0, 0, 0 [25] => 5, 0, 0, 0 [30] => 6, 0, 0, 0 [35] => 7, 0, 0, 0 [40] => 8, 0, 0, 0 [45] => 9, 0, 0, 0 [50] => 10, 0, 0, 0 [55] => 11, 0, 0, 0 [60] => 12, 0, 0, 0 [65] => 13, 0, 0, 0 [70] => 14, 0, 0, 0 [75] => 15, 0, 0, 0 [80] => 16, 0, 0, 0 [85] => 17, 0, 0, 0 [90] => 18, 0, 0, 0 [95] => 19, 0, 0, 0 [100] => 20, 0, 0, 0 [105] => 21, 0, 0, 0 [110] => 22, 0, 0, 0 [115] => 23, 0, 0, 0 [120] => 24, 0, 0, 0 [125] => 25, 0, 0, 0 [130] => 26, 0, 0, 0

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.08 ms | 409 KiB | 8 Q