/**
* 将一个数值切成N份
* @param int $number 切的数值
* @param int $avgNumber 份数
* @return array
*/
function numberAvg($number, $avgNumber)
{
if ($number == 0) {
$array = array_fill(0, $avgNumber, 0);
} else {
$avg = floor($number / $avgNumber);
$ceilSum = $avg * $avgNumber;
$array = array();
for ($i = 0; $i < $avgNumber; $i++) {
if ($i < $number - $ceilSum) {
array_push($array, $avg + 1);
} else {
array_push($array, $avg);
}
}
}
return $array;
}
标签:切成,avgNumber,number,数值,param,数组,array,返加
From: https://www.cnblogs.com/fuqian/p/17612481.html