echo 'Output is: ';
foreach (xrange(1, 7, 2) as $num) {
echo "$num";
}
?>
" class="related-a">
What will be the output of the following PHP 7.1 code snippet?
<?php
function xrange($first, $last, $forward = 1)
{ if ($first < $last) {
if ($forward <= 0) {
throw new LogicException('The value of forward should be positive');
}
for ($i = $first; $i <= $last; $i += $forward){
yield $i;
}
} else {
if ($forward >= 0) {
throw new LogicException('The value of forward should be negative');
}
for ($i = $first; $i >= $last; $i += $forward){
yield $i;
}
}
}
echo "\n";
echo 'Output is: ';
foreach (xrange(1, 7, 2) as $num) {
echo "$num";
}
?>