pi
Returns the number pi.
Syntax
pi(): floatReturn value
floatThe value of pi.
Examples
The area of a circle with radius 2:
<?php
echo round(pi() * 2 ** 2, 2);Output:
12.57The M_PI constant holds the same value:
<?php
var_dump(pi() === M_PI);Output:
bool(true)Notes
Expressions usually use the M_PI constant — it is shorter and needs no function call.
See also
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.