find the surface area of a cone in php

To find the surface area of a cone in PHP, you can use the mathematical formula:

surface area = pi * r * (r + sqrt(h^2 + r^2))

where r is the radius of the base of the cone and h is the height of the cone.

Here's the PHP function that calculates the surface area of a cone:

main.php
function cone_surface_area($radius, $height) {
  $surface_area = pi() * $radius * ($radius + sqrt(pow($height, 2) + pow($radius, 2)));
  return $surface_area;
}
161 chars
5 lines

To use the function, simply pass in the radius and height of the cone as arguments:

main.php
$radius = 5;
$height = 10;

$surface_area = cone_surface_area($radius, $height);

echo "The surface area of the cone is: " . $surface_area;
140 chars
7 lines

This will output:

main.php
The surface area of the cone is: 219.91148575129
49 chars
2 lines

gistlibby LogSnag