Monday, April 30, 2012

Dividing a integer equally in X parts

I'm looking for a efficient way in PHP to divide a number in equal part. Number will always be integer (no float).



Let's say that I have an array $hours with values from "1" to "24" ($hours['1'], etc) and a variable $int containing an integer. What I want to acheive is spreading the value of $int equally in 24 parts so I can assing the value to each corresponding array entries. (Should the number be odd, the remaining would be added to the last or first values in the 24).



Regards,





No comments:

Post a Comment