find the surface area of a triangular prism in php

To find the surface area of a triangular prism in PHP, you need to first know the formula. The formula for the surface area of a triangular prism is:

SA = 2*(0.5bh) + L*(a+b+c)

Where SA is the surface area, L is the length, a, b, and c are the sides of the triangle base, b is the triangle base and h is the height of the triangle.

To calculate the surface area of a triangular prism in PHP, you can create a function that takes the length, the triangle base, and the height of the triangle as arguments. Here is an example implementation of the function:

main.php
function surface_area_of_triangular_prism($length, $base, $height) {
    // calculate the area of the triangle base
    $area_base = 0.5 * $base * $height;
    
    // calculate the perimeter of the triangle base
    $perimeter_base = $base + 2 * sqrt(pow($base/2,2) + pow($height,2));
    
    // calculate the surface area
    $surface_area = 2 * $area_base + $perimeter_base * $length;
    
    return $surface_area;
}
422 chars
13 lines

Then, you can call the function by passing the values of the length, triangle base, and height of the triangle:

main.php
$surface_area = surface_area_of_triangular_prism(5, 8, 10);

echo "The surface area of the triangular prism is " . $surface_area;
130 chars
4 lines

This will output:

main.php
The surface area of the triangular prism is 296.70377387092
60 chars
2 lines

gistlibby LogSnag