我需要填写与数字的阵列,几个例子:填充阵列与具体的数字
nbreParChargement = 4; 10
- 预期输出:
$niveaux = array(4,4,2);
4 + 4 + 2 = 10
- 预期输出:
nbreParChargement = 6; 14
- 预期输出:
$niveaux = array(6,6,2);
6 + 6 + 2 = 14
- 预期输出:
nbreParChargement = 16; 13
- 预期输出:
$niveaux = array(13);
13 = 13
- 预期输出:
nbreParChargement = 4;对于30
- 预期输出:
$niveaux = array(4,4,4,4,4,4,4,2);
4 + 4 + 4 + 4 + 4 + 4 + 4 + 2 = 30
- 预期输出:
我试图解决,但我不知道完美的解决方案:
function chargement($nbre, $nbreParChargement){
$niveaux = array();
for($i=0; $i<=$nbre; $i++){
$niveaux[$i] = $i + $nbreParChargement;
}
}
这些数字的规则是什么?随机数字?符合公式的数字? – Bonatti
请记住要将变量和函数名称翻译成英文,否则非法语的用户可能很难弄清楚您的代码。 –