This article illustrates the simple method of realizing the pi in PHP. Share to everyone for your reference, specific as follows:
The previous article "C Language for PI" gives a simple calculation method of pi, here for reference to the previous code to the calculation method of the PHP pi. The specific code is as follows:
<?php
$t =1;
$pi =0;
$n =1.0;
$s =1;
while (ABS ($t) >1e-6)
{
$pi = $pi + $t;
$n = $n +2;
$s =-$s;
$t = $s/$n;
}
$pi = $pi *4;
printf ("pi=%10.6f", $pi);
? >
The result of the operation is:
Add: small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout, increase the readability of the code:
PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat
In addition, because PHP belongs to the C language style, the following tool can also be used to format PHP code :
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site topics: "PHP Math Arithmetic Skills summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP Array" operation Skills Encyclopedia, " Summary of the PHP sorting algorithm, "PHP commonly used traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.