PHP pi( ) Function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report While solving mathematical problems we often come across questions which requires the value of π. Manually inserting the value of PI (π) can be time-consuming and erroneous. It is also not considered as a good programming practice. To solve this issue a built-in function of PHP pi() comes to aid. The pi() function in PHP is used to return the value of π . Also, M_PI is a named constant PHP which gives identical value to that of returned by pi() function. It is slightly faster than the pi() function. Some other predefined named constants related to π are : M_PI_2 : It describes π/2. Its value is 1.570796. M_PI_4 : It describes π/4. Its value is 0.785398. M_1_PI : It describes 1/π. Its value is 0.318309. M_PI : It describes π. Its value is 3.141592. M_2_PI : It describes 2/π. Its value is 0.636619. M_SQRTPI : It describes sqrt(π). Its value is 1.772453. M_2_SQRTPI : It describes 2/sqrt(π). Its value is 1.128379. Syntax: float pi() Parameters: This function does not accept any parameter. Return Value: It returns a floating point value which is an approximate value of PI. Examples: Input : echo(pi()) Output : 3.1415926535898 Input : echo M_PI Output : 3.1415926535898 Below programs illustrate the pi() function in PHP: When pi() function is used: PHP <?php echo(pi()); ?> Output: 3.1415926535898 When M_PI is used for finding the value of PI: PHP <?php echo M_PI; ?> Output: 3.1415926535898 Important Points To Note: The pi() function can be used to return the value of π. M_PI is a named constant which is slightly faster than the pi() function. pi() function returns the value of pi as float. Reference: http://php.net/manual/en/function.pi.php Comment More infoAdvertise with us Next Article PHP pi( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-math PHP-function +1 More Practice Tags : Misc Similar Reads PHP pos() Function The pos() is an inbuilt function in PHP which is used to return the value of the element in an array which the internal pointer is currently pointing to. The pos() function does not increment or decrement the internal pointer after returning the value. In PHP all arrays have an internal pointer. Thi 2 min read PHP | time() Function The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP. Syntax: int time() Parameter: This function does not accepts any parameter 2 min read PHP trim() Function The trim() function in PHP is an inbuilt function which removes whitespaces and also the predefined characters from both sides of a string that is left and right. Related Functions: PHP | ltrim() Function PHP | rtrim() Function Syntax: trim($string, $charlist) Parameters:The function accepts one man 2 min read PHP | Functions A function in PHP is a self-contained block of code that performs a specific task. It can accept inputs (parameters), execute a set of statements, and optionally return a value. PHP functions allow code reusability by encapsulating a block of code to perform specific tasks.Functions can accept param 8 min read PHP | print_r() Function The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable. Syntax: print_r( $variable, $isStore ) Parameters: This function accepts two parameters as shown in above syntax and described below. $variable: This parameter specifies the variabl 2 min read Like