ricky spires Posted September 4, 2012 Share Posted September 4, 2012 hello. how do i get how many 30's there are in x amount and then strip the remainder in 29 there is 0 in 59 there is 1 Quote Link to comment https://forums.phpfreaks.com/topic/267987-how-do-i-get-how-many-30s-there-are-in-x-amount-and-then-strip-the-remainder/ Share on other sites More sharing options...
MMDE Posted September 4, 2012 Share Posted September 4, 2012 hello. how do i get how many 30's there are in x amount and then strip the remainder in 29 there is 0 in 59 there is 1 floor($x/30); Quote Link to comment https://forums.phpfreaks.com/topic/267987-how-do-i-get-how-many-30s-there-are-in-x-amount-and-then-strip-the-remainder/#findComment-1375106 Share on other sites More sharing options...
DavidAM Posted September 5, 2012 Share Posted September 5, 2012 $count = 0; while ($x >= 30) { $count = $count + 1; $x = $x - 30; } unset($x); echo $count; Quote Link to comment https://forums.phpfreaks.com/topic/267987-how-do-i-get-how-many-30s-there-are-in-x-amount-and-then-strip-the-remainder/#findComment-1375322 Share on other sites More sharing options...
Psycho Posted September 5, 2012 Share Posted September 5, 2012 $count = 0; while ($x >= 30) { $count = $count + 1; $x = $x - 30; } unset($x); echo $count; That's too efficient. You need to step through one by one $count = 0; $subCount = 0; for ($i=0; $i<$x; $i++) { $subCount++; if($subCount==30) { $count = $count + 1; $subCount = 0; } } echo $count; Quote Link to comment https://forums.phpfreaks.com/topic/267987-how-do-i-get-how-many-30s-there-are-in-x-amount-and-then-strip-the-remainder/#findComment-1375327 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.