schme16 Posted April 16, 2007 Share Posted April 16, 2007 Can php understand if a number is a perfect division of five (i want it to do five things then alter slightly the do another five things) i've got as far as: <?php $x = 0 while($x == *code for division of five*) {$x++;} ?> Quote Link to comment https://forums.phpfreaks.com/topic/47225-solved-divisions-of-5/ Share on other sites More sharing options...
dwees Posted April 16, 2007 Share Posted April 16, 2007 if (round($x/5) == $x/5) { // Do your stuff } or if ($x % 5 == 0 ) { // Do your stuff } Quote Link to comment https://forums.phpfreaks.com/topic/47225-solved-divisions-of-5/#findComment-230304 Share on other sites More sharing options...
obsidian Posted April 16, 2007 Share Posted April 16, 2007 if ($x % 5 == 0 ) { // Do your stuff } I agree that the modulous operator is what you're after. You can compare like that, or you can simply loop through and keep a counter to do something every 5 repetitions: <?php for ($i = 1; $i <= 150; $i++) { if ($i % 5 == 0) { echo "Fifth repetition<br />\n"; } else { echo "...<br />\n"; } } ?> Have fun! Quote Link to comment https://forums.phpfreaks.com/topic/47225-solved-divisions-of-5/#findComment-230310 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.