richiejones24 Posted February 29, 2012 Share Posted February 29, 2012 I need to double a number each loop but cant find a way to do it, so eg, 500, 1000,2000,4000 ect Link to comment https://forums.phpfreaks.com/topic/257978-doubling-number-each-loop/ Share on other sites More sharing options...
sunfighter Posted February 29, 2012 Share Posted February 29, 2012 <?php $number = 3; for($i = 0; $i < 50; $i++) { $number = 2 * $number; echo $number . '<br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/257978-doubling-number-each-loop/#findComment-1322379 Share on other sites More sharing options...
Zane Posted February 29, 2012 Share Posted February 29, 2012 There's also a multiplication assignment operator.. *= so you can easily just say $number *= 2; Link to comment https://forums.phpfreaks.com/topic/257978-doubling-number-each-loop/#findComment-1322396 Share on other sites More sharing options...
Recommended Posts