I am using PHP generator and can't explain this behavior. This is the code I tried
<!-- language: PHP -->
<?php
function myfun($num1, $num2, $ctr = 1) {
for ($i = $num1; $i <= $num2; $i =+ $ctr) {
yield $i;
}
}
echo 'Odd numbers: ';
foreach(myfun(1, 7, 2) as $num) {echo $num;};
?>
Can someone explain me this behavior using PHP yield, entering a infinite loop?
result: Odd numbers: 122222222222222222222222222222222...............
Note: $i += $ctr works as expected
result: Odd numbers: 1357
$i =+ $ctris the same as$i = $ctr.+ some numberis essentially a no-op.