-1
我有这个JavaScript公式,我现在正试图转换为PHP。来自JavaScript的PHP公式
的JavaScript:
LVL=new Array();
LVL[1]=128;
LVL[0]=128;
m=.05;
for (i=1;i<101;i++) {
if (i>1) {
LVL[i]=Math.floor(LVL[i-1]+(LVL[i-1]*m));
m=m+.0015;
}
}
那么它是一堆的table
和for loop
的document.writes
。
这里是我到目前为止(不工作):
<?php
$n = 1; // level
$m = .05; // exp modifier
$exp = floor($n*1+($n-1)*$m);
echo "Level " . $n . ", exp needed: " . $exp; // 128 exp
?>
PHP的输出是:Level 1, exp needed: 1
,这就是错误的。
它应该说:Level 1, exp needed: 128
我在做什么错?
你忘了for循环... – 2011-01-09 01:11:59
哪有`1 * 1 +(1-1)* 0.05`是`128`?在你的PHP代码中你没有事件`128`(而你的JS代码中有`128`)。你的PHP代码看起来完全不同... – 2011-01-09 01:12:29
我不需要循环,因为它只是公式。 – nn2 2011-01-09 01:25:46