Dividing a integer equally in X parts
Here's the algorithm you're looking for; it evenly spreads an integer N
over K
cells:
for i = 0 to K
array[i] = N / K # integer division
# divide up the remainder
for i = 0 to N mod K
array[i] += 1
Try this code
<?php
$num = 400;
$val = floor($num/24);
for($i=0;$i<24;$i++) {
$arr[$i] = $val;
}
$arr[0] += $num - array_sum($arr);
?>