@ 2015-10-23T21:07:36Z <?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();
yield from [1, 2, 3];
}
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 $val) {
echo "Iteration!\n";
var_dump($val);
}
echo "Done with iteration\n";
}
function sendingTest($g) {
$g->next();
$g->send(10);
$g->send(20);
}
iterationTest(yfiterator());
//iterationTest(yfeiterator());
// iterationTest(gen1());
echo "Done with all tests\n";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 About to start iteration
Iteration!
int(1)
Iteration!
int(2)
Iteration!
int(3)
Iteration!
int(1)
Iteration!
int(2)
Iteration!
int(3)
Done with iteration
Done with all tests
Output for 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/6eT0o on line 4
Process exited with code 255 . preferences:dark mode live preview
208.74 ms | 402 KiB | 269 Q