onedumbcoder Posted May 23, 2008 Share Posted May 23, 2008 is there a way to determine if something is divisible by 4? for example i want to be to add to a counter when a number is divisible by 4; so 1 2 3 4 counter++; 5 6 7 8 counter++; 9 10 11 12 counter++ 13... and so on Link to comment https://forums.phpfreaks.com/topic/106968-solved-divisible-by-4/ Share on other sites More sharing options...
effigy Posted May 23, 2008 Share Posted May 23, 2008 <pre> <?php foreach (range(1, 40) as $num) { printf('%02d ', $num); if ($num % 4 == 0) { echo '<br>'; } } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/106968-solved-divisible-by-4/#findComment-548293 Share on other sites More sharing options...
.josh Posted May 23, 2008 Share Posted May 23, 2008 $max = 100; // some random number to be counted to $counter = 0; // initialize counter for ($x = 1; $x < $max; $x++) { // loop to count to whatever // % is called modulus it divides $x by 4 and returns a remainder if ($x % 4 == 0) { // if the remainder is 0.... $counter++; // add 1 to the counter } // end if } // end for Link to comment https://forums.phpfreaks.com/topic/106968-solved-divisible-by-4/#findComment-548297 Share on other sites More sharing options...
onedumbcoder Posted May 23, 2008 Author Share Posted May 23, 2008 thank you so much. Link to comment https://forums.phpfreaks.com/topic/106968-solved-divisible-by-4/#findComment-548299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.