To find the volume of a sphere in PHP, we can use the following formula:
main.php21 chars2 lines
Where V
is the volume of the sphere, r
is the radius, and pi
is the mathematical constant pi.
Here's the PHP code to calculate the volume of a sphere of radius r
:
main.php168 chars9 lines
In the above code, we have initialized the radius of the sphere as $r
. We have also defined the mathematical constant pi
as $pi
. Then, we have used the above formula to calculate the volume of the sphere and stored it in the variable $volume
. Finally, we have printed the volume of the sphere using the echo
statement.
You can change the value of $r
to calculate the volume of the sphere for any other radius.
gistlibby LogSnag