PHP pi() Function

Definition and Usage

The pi () function returns the value of mathematical constant Π. It returns a float value 3.14159265359 which is equal to predefined constant defined in PHP - M_PI

Syntax

pi ( void ) : float

Parameters

This function requires no parameters

Return Values

PHP pi() function returnsthe mathematical constant Π and is equal to predefined mathematical constant M-PI. Instead of using M_PI, we can use pi() function in mathematical expressions.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

<?php
   echo "sqrt(pi) = " . sqrt(pi());
   echo " M_SQRTPI = " . M_SQRTPI . "
";    echo "2/sqrt(pi) = " . 2/sqrt(pi());    echo " M_2_SQRTPI = ". M_2_SQRTPI; ?>

Output

This will produce following result −

sqrt(pi) = 1.7724538509055 M_SQRTPI = 1.7724538509055
2/sqrt(pi) = 1.1283791670955 M_2_SQRTPI = 1.1283791670955
Updated on: 2026-03-11T23:22:53+05:30

528 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements