Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
PHP pi() Function
The pi() function returns the value of mathematical constant ? (pi). It returns a float value 3.14159265359 which is equal to the predefined constant M_PI in PHP.
Syntax
pi() : float
Parameters
This function requires no parameters.
Return Value
The pi() function returns the mathematical constant ? as a float value. This is equivalent to using the predefined constant M_PI, providing a convenient function-based alternative for mathematical calculations.
Example
Here's how to use the pi() function in mathematical calculations −
<?php
echo "pi() = " . pi() . "<br>";
echo "M_PI = " . M_PI . "<br>";
echo "sqrt(pi) = " . sqrt(pi()) . "<br>";
echo "M_SQRTPI = " . M_SQRTPI . "<br>";
echo "2/sqrt(pi) = " . 2/sqrt(pi()) . "<br>";
echo "M_2_SQRTPI = " . M_2_SQRTPI . "<br>";
echo "Area of circle (radius=5): " . pi() * 5 * 5;
?>
The output of the above code is −
pi() = 3.1415926535898 M_PI = 3.1415926535898 sqrt(pi) = 1.7724538509055 M_SQRTPI = 1.7724538509055 2/sqrt(pi) = 1.1283791670955 M_2_SQRTPI = 1.1283791670955 Area of circle (radius=5): 78.539816339745
Conclusion
The pi() function provides a simple way to access the mathematical constant ? in PHP calculations. It's functionally identical to M_PI but offers a more readable function-based syntax for mathematical operations.
