FD_F Posted February 15, 2009 Share Posted February 15, 2009 how can i do for($d=0;$d<$i;$d++) $i can be 20 for example starting from 0, that will give output every 7 counts Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/ Share on other sites More sharing options...
allworknoplay Posted February 15, 2009 Share Posted February 15, 2009 Well I don't know how often you want your loop to run? But let's say it loops 30 times. $i = 30; for ($d=0;$d<$i;$d++) { if($d == 7 || $d == 14 || $d == 21) { echo "something"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/#findComment-762972 Share on other sites More sharing options...
FD_F Posted February 15, 2009 Author Share Posted February 15, 2009 thanks for the idea but i dont know how often the loop runs it culd be even 150 times Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/#findComment-762976 Share on other sites More sharing options...
allworknoplay Posted February 15, 2009 Share Posted February 15, 2009 thanks for the idea but i dont know how often the loop runs it culd be even 150 times Well my "for loop" works. All you have to do is just implement a calculation that correctly identifies multiples of 7.... Then put the numerical answers into an array. And during the loop check the array values and if they appear, then do an echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/#findComment-762980 Share on other sites More sharing options...
genericnumber1 Posted February 15, 2009 Share Posted February 15, 2009 You can do something like.. <?php for($i = 0; $i < 50; ++$i) { if($i % 7 == 0) { echo $i; } } Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/#findComment-762985 Share on other sites More sharing options...
Cosizzle Posted February 15, 2009 Share Posted February 15, 2009 genericnumber1 beat me to it but is correct, made this test. $i = 30; $divNum = 7; for ($d=0; $d<$i; $d++) { // something happening echo 'count = '.$d.'<br/>'; echo 'divNum = '.$d % $divNum; echo '<br/>'; if ($d % $divNum == 0) { echo 'true<br/>'; } echo '<hr>'; } Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/#findComment-762994 Share on other sites More sharing options...
FD_F Posted February 15, 2009 Author Share Posted February 15, 2009 thanks for all the explains Quote Link to comment https://forums.phpfreaks.com/topic/145334-solved-for-loop-echo-every-7-counts/#findComment-763003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.