如何设置具有特定除法数的数组的值


How do I set the value for an array with specific number of division

如何设置一个数组的值,其中除法为特定的数字,其余的数字将被环回。

<?php
    $total = 125;
    $divide = 15;
    for($a=0; $a<=$divide; $a++)
    {
        $b[] = .....; //  $total/$divide
    }
print_r($b);
?>

输出:

array([0]=>9[1]=>9[2]=>9[3]=>9[4]=>9[5]=>8[6]=>8[7]=>8..[14]=>8)

例如

$total = 125;
$size = 15;
$chunk = floor($total / $size);
$mod = $total % $size;
if($mod)
    $result = array_fill(0, $mod, $chunk + 1) +
        array_fill($mod, $size - $mod, $chunk);
else
    $result = array_fill(0, $size, $chunk);