There are mathematical formulas to find the area of the triangle. To find the area of a triangle first we have to get the base value and the height value of the triangle and use the formula
(base * height) / 2
. For example, if the base of the triangle is 7 and the height of the triangle is 9 then the area of the triangle will be
(7 * 9) / 2 which will be 31.5.
In PHP there are many ways to find the area of the triangle. In this program, we first have to read the base value and the height value from the user and assign it to variables b and h, and to find the area we have to use the formula
(base * height) / 2.
Step 1: Read the base value into the variable b
Step 2: Read the height value into the variable h
Step 3: Assign the computed value of '(b * h) / 2' to the variable a
Step 4: Print the value of the variable a as the area of the triangle
<?php $b = readline("Enter the base value: "); $h = readline("Enter the height value: "); $a = ($b * $h) / 2; echo "Area with base $b and height $h = $a"; ?>
Enter the base value: 5 Enter the height value: 7 Area with base 5 and height 7 = 17.5