3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { $x = yield 1; echo "Sup!\n"; $y = yield 2; var_dump($x + $y); } function yfgenerator() { yield from gen1(); echo "Dawg\n"; yield from gen1(); } function yfeiterator() { $arr = [1, 2, 3]; foreach($arr as $val) { yield $val; } } function yfiterator() { yield from []; yield from [1, 2, 3]; /**/ yield from array( "first" => 1, "second" => 2, "third" => 3, ); /**/ } function iterationTest($g) { echo "About to start iteration\n"; foreach($g as $key => $val) { echo "Iteration!\n"; var_dump($key); var_dump($val); } echo "Done with iteration\n"; } function sendingTest($g) { $g->send(10); var_dump($g->current()); $g->send(20); var_dump($g->current()); } //iterationTest(yfiterator()); // iterationTest(gen1()); sendingTest(yfiterator()); sendingTest(yfgenerator()); echo "Done with all tests\n";

preferences:
52.27 ms | 402 KiB | 5 Q