PHP Function Reference

PHP pi() Function



The PHP pi() function returns the value of 𝜋 to the available precision. It returns the value of 𝜋 as 3.1415926535898. Please note that, M_PI constant yields the identical results to pi() function.

Syntax

pi()

Parameters

No parameter is required.

Return Value

Returns the value of PI, i.e., 3.1415926535898

Example:

In the example below, pi() function is used to calculate the area of a circle.

<?php
$x = 5; 
$area = pi()*$x*$x;

echo "Value of the pi() is: ".pi()."\n";
echo "Value of the M_PI is: ".M_PI."\n";
echo "Area of the circle with radius $x is: ".$area."\n";
?>

The output of the above code will be:

Value of the pi() is: 3.1415926535898
Value of the M_PI is: 3.1415926535898
Area of the circle with radius 5 is: 78.539816339745

❮ PHP Math Reference