3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRunningTotal(array $array) { $generator = function(array $array) { $total = 0; foreach ($array as $key => $value) { $total += $value; yield $key => $total; } }; return iterator_to_array($generator); } $a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var_dump(getRunningTotal($a));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: iterator_to_array(): Argument #1 ($iterator) must be of type Traversable|array, Closure given in /in/GT60Z:10 Stack trace: #0 /in/GT60Z(10): iterator_to_array(Object(Closure)) #1 /in/GT60Z(15): getRunningTotal(Array) #2 {main} thrown in /in/GT60Z on line 10
Process exited with code 255.

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