Lazy Line · Level 5 of 8

The receipt

A generator that yields items and then returns a total.

<?phpfunction total() {    $sum = 0;    foreach ([1, 2, 3] as $n) {        $sum += $n;        yield $n;    }    return $sum;}$gen = total();foreach ($gen as $n) {    echo "item $n" . PHP_EOL;}echo 'total ' . $gen->getReturn() . PHP_EOL;

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…
  4. 4…