このコードがあるとしましょう:
<?php
$aLevel[] = 98;
function experience($L) {
$a=0;
for($x=1; $x<$L; $x++) {
$a += floor($x+300*pow(2, ($x/7)));
$aLevel[$x-1] = $a; // we minus one to comply with array
}
return floor($a/4);
}
for($L=1;$L<100;$L++) {
echo 'Level '.$L.': '. number_format(experience($L)). '<br />';
}
echo $aLevel[0]; // Level 1 should output 0 exp
echo "<br />" . $aLevel[1]; // Level 2 should output 83 exp
// et cetera
?>
expを格納する配列を作成しようとしています。したがって、レベル 1$aLevel[0]
で EXP は (当然) 0 になり、レベル 2$aLevel[1]
で EXP は 83 などになります。
以下のコード...動作します。経験とレベルのループは機能しますが、配列は機能しません。
私は何を間違っていますか?