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…
- 2…
- 3…
- 4…