- range: documentation ( source)
<?php
function xrange($start, $limit, $step = 1) {
if ($start < $limit) {
if ($step <= 0) {
throw new LogicException('Step must be +ve');
}
echo $step;
for ($i = $start; $i <= $limit; $i += $step) {
yield $i;
echo 'iter' . $i;
}
}
}
/*
* Note that both range() and xrange() result in the same
* output below.
*/
echo 'Single digit odd numbers from range(): ';
foreach (range(1, 9, -5) as $number) {
echo $number;
}