Labels on the items
One generator yields key => value pairs; another yields plain values.
<?phpfunction prices() { yield 'tea' => 2; yield 'soup' => 5;}foreach (prices() as $name => $price) { echo "$name costs $price" . PHP_EOL;}function plain() { yield 'a'; yield 'b';}foreach (plain() as $k => $v) { echo "$k => $v" . PHP_EOL;}1. Predict the output
Tap the lines in the order you think they print.
- 1…
- 2…
- 3…
- 4…