- array_shift: documentation ( source)
<?php
function routeIterator(&$path) {
while (!empty($path)) {
yield $path[0];
array_shift($path);
}
}
function exampleGenerator($path) {
foreach ($routeIterator($path) as $chunk) {
yield "Chunk: " . $chunk;
echo " Sent value: " . yield . "\n";
}
}
foreach (exampleGenerator([1,2,3,4,5]) as $signal) {
echo $signal;
}