AbydosGater Posted December 25, 2006 Share Posted December 25, 2006 Hi GuysMerry Xmas to you all!Ive been trying to play with while loops, been some time since i have used them, and i needed to type out a list that went from 1, to 150 like 1,2,3..... so i came up with..[code]<?php$cnum = 1;while ($cnum <= 150){$num = $cnum++;$cnum .= ",$num";}print $cnum;?>[/code]But when i run this its not stopping its putting big strain on my server, anyone see where i went wrong?Thanks-Andy Link to comment https://forums.phpfreaks.com/topic/31823-solved-while-loop-gone-madp/ Share on other sites More sharing options...
kenrbnsn Posted December 25, 2006 Share Posted December 25, 2006 You're never incrementing $cnum, so you're loop is never ending. Try this:[code]<?php$tmp = array();for ($cnum=1;$cnum<151;$cnum++) $tmp[] = $cnum;echo implode(', ',$tmp);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31823-solved-while-loop-gone-madp/#findComment-147565 Share on other sites More sharing options...
AbydosGater Posted December 26, 2006 Author Share Posted December 26, 2006 Thanks Ken Worked Great!-Andy Link to comment https://forums.phpfreaks.com/topic/31823-solved-while-loop-gone-madp/#findComment-147906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.