Perimeter: The perimeter is the length of the outline of a shape. To find the perimeter of a rectangle or square you have to add the lengths of all the four sides. x is in this case the length of the rectangle while y is the width of the rectangle.
Area: The area is measurement of the surface of a shape. To find the area of a rectangle or a square you need to multiply the length and the width of a rectangle or a square.
Result:
PHP Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?php $area=0; $perimeter=0; $len=""; $wid=""; if(isset($_POST["calcBtn"])) { $len= $_POST["len"]; $wid= $_POST["wid"]; //area formule length*width $area=$len*$wid; //perimeter formule 2*(length+width) $perimeter=2*($len+$wid); } ?> <!doctype html> <html> <head> <title>Code4Examples</title> <meta charset="utf-8"> <style> label{ display: block; } </style> </head> <body> <h1>Area and Perimeter of Rectangle</h1> <h2>Area: <?=$area?></h2> <h2>Perimeter:<?=$perimeter?></h2> <form action="" method="post"> <label for="len">Length: <input type="text" name="len" value="<?=$len?>"> </label> <label for="wid">Width: <input type="text" name="wid" value="<?=$wid?>"> </label> <button name="calcBtn" type="submit">Calculate</button> </form> </body> </html> |
[…] Calculate Area and Perimeter of Rectangle in PHP […]