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++;} ?> 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 } 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! Link to comment https://forums.phpfreaks.com/topic/47225-solved-divisions-of-5/#findComment-230310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.