在php中使用pow

时间:2013-08-12 12:13:01

标签: php math pow

我可以使用pow而不是像这样写吗?

                    $round1 = $max / 2;
                    $round2 = $round1 + ($max / 2 / 2);
                    $round3 = $round2 + ($max / 2 / 2 / 2);
                    $round4 = $round3 + ($max / 2 / 2 / 2 / 2);
                    $round5 ...
                    $final = $max - 1;
                    $third = $max;

感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

您可能不会想要更简单的方法来执行此操作,是否:

$round = array($max/2);
for ($i=1;i<$max;$i++)
{
    $round[] = $round[$i -1] + $max/pow(2, $i + 1);
}

当然,array_sum也值得一看。

答案 1 :(得分:-1)

试试这个,

 $rount[0]=0;
 for($i=1;$1<upto n rounds;$i++)
 {
   $rount[i]=$round[i-1]+($max/(2*i));
 }