Question from the PHP7 test

Write a PHP code that prints 1, 2, 3, 4

Medium

What will this code display?

<?php
function gen()
{
    yield 1;
    yield 2;
    yield from gen2();
}

function gen2()
{
    yield 3;
    yield 4;
}

foreach(gen() as $val)
{
    echo $val, PHP_EOL;
}
Author: Julien BreuxStatus: PublishedQuestion passed 1122 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!