+ 1

Php loop

<?php $i = 1; while ($i < 10) { echo "The value is $i <br />"; $i=+2; } ?> whats wrong with this code it executes continously

21st Sep 2017, 4:20 PM
Maamun Maamun
Maamun Maamun - avatar
3 Answers
+ 9
$i = +2 means $i = 2. As 2 is less than 10, it's an infinite loop.
21st Sep 2017, 4:22 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 1
xo in php you cant use =+ to increment like other languages?
21st Sep 2017, 4:24 PM
Maamun Maamun
Maamun Maamun - avatar
+ 1
$i+=2
21st Sep 2017, 4:24 PM
Yaroslav Pieskov
Yaroslav Pieskov - avatar