I am trying to learn range and xrange functionality by plugging PHP.net code into a code generator. When I run the following code I am given the error:
unexpected '$i' (T_VARIABLE) on line 4
Here is the code:
function xrange($start, $limit, $step) {
if ($start < $limit) {
for ($i = $start; $i <= $limit; $i += $step) {
yield $i;
}
} else {
for ($i = $start; $i >= $limit; $i -= $step) {
yield $i;
}
}
}
foreach (range(1, 9, 2) as $number) {
echo "$number ";
}
Thanks in advnace for your insight!