好的,这只是我和我的同事在玩耍的东西。我们知道PHP有自己的PI函数,但这是出于理论和好奇心而产生的。
所以我们想知道PHP是否能够计算pi
,以及如何计算。
pi
的公式为π= 4/1 - 4/3 + 4/5 - 4/7 + 4/9...
以下是我们做的:
$theValue = 100;// the max
for ($i=1; $i<$theValue; $i++){
if ($i % 2 == 1){
$iWaardes[] = 4 / $i; // divide 4 by all uneven numbers and store them in an array
}
}
// Use the array's $keys as incrementing numbers to calculate the $values.
for ($a=0, $b=1, $c=2; $a<$theValue; $a+=3, $b+=3, $c+=3 ){
echo ($iWaardes[$a] - $iWaardes[$b] + $iWaardes[$c]).'<br>';
}
现在我们有一个循环计算了第一组4/1 - 4/3 + 4/5
,但它停在那里,然后重新开始以下的3个序列。如何使其运行整个$theValue
并计算整个序列?
请记住,这只是一个有趣的实验,不要当真。
$theValue
时,整个输出都会改变。 - Interactivepi
。 - ishegg