3v4l.org

run code in 300+ PHP versions simultaneously
<?php function powerSet(Iterator $iterator){ if(!$iterator->valid()){ return yield new EmptyIterator(); } $one = $iterator->current(); $rest = new NoRewindIterator($iterator); $rest->next(); foreach(powerSet($rest) as $set){ $set = iterator_to_array($set); yield new ArrayIterator($set); // why does this work yield (function($set, $one){ yield from array_merge($set, [$one]); })($set, $one); // but this doesn't? // yield (function($set, $one){ // yield from $set; // yield $one; // })($set, $one); } } function baz(){ yield 1; yield 2; yield 3; yield 4; } $sets = powerSet(baz()); foreach($sets as $i => $set){ echo $i+1 . " {"; $arr = iterator_to_array($set); echo implode(", ", $arr); echo "}\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
1 {} 2 {1} 3 {2} 4 {2, 1} 5 {3} 6 {3, 1} 7 {3, 2} 8 {3, 2, 1} 9 {4} 10 {4, 1} 11 {4, 2} 12 {4, 2, 1} 13 {4, 3} 14 {4, 3, 1} 15 {4, 3, 2} 16 {4, 3, 2, 1}

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:
64.9 ms | 401 KiB | 8 Q