find the area of a trapezoid in php

To calculate the area of a trapezoid in PHP, you can use the following formula:

main.php
area = ((b1 + b2) * h) / 2
27 chars
2 lines

where b1 and b2 are the lengths of the parallel sides, and h is the distance between them.

Here is the PHP code to calculate the area of a trapezoid:

main.php
<?php
// declare variables
$b1 = 10;
$b2 = 7;
$h = 5;

// calculate the area
$area = (($b1 + $b2) * $h) / 2;

// display the result
echo "The area of the trapezoid is: " . $area;

?>
183 chars
14 lines

In this example, the base lengths are 10 and 7, and the height is 5. The code calculates the area of the trapezoid using the formula mentioned above and displays the result as output.

related categories

gistlibby LogSnag