- var_dump: documentation ( source)
<?php
function stack(... $items)
{
foreach ($items as $item) {
if ($next = yield $item) {
yield from stack(... $next);
} else {
yield $next;
}
}
}
$items = [1,2,3];
$stack = stack(...$items);
foreach ($stack as $item) {
if ($item == 1) {
$stack->send(['negate', -$item]); // push something onto the stack
}
if ($item == 2) {
continue; // remove something from the stack
}
if ($item == 3) {
$stack->send(['exponential', $item ** 2]); // push something onto the stack
}
if (isset($item)) {
var_dump($item);
}
}