your image

PHP Area of Rectangle Program - javatpoint

javapoint
Related Topic
:- PHP

Area of a Rectangle

Area of a rectangle is calculated by the mathematical formula,

  1. Length ∗ Breadth = Area  

Logic:

  • Take two variables.
  • Multiply both of them.

Area of Rectangle in PHP

Program to calculate area of rectangle with length as 14 and width as 12 is shown.

Example:

 

History of Java

  1. <?php  
  2.  $length = 14;  
  3.  $width = 12;  
  4.  echo "area of rectangle is $length * $width= " . ($length * $width) . "<br />";  
  5.   ?>  

Output:

Area of Rectangle with Form in PHP

Program to calculate area of rectangle by inserting values in the form is shown.

Example:

  1. <html>  
  2. <body>  
  3. <form method = "post">   
  4. Width: <input type="number" name="width">   
  5. <br><br>   
  6. Length: <input type="number" name="length"> <br>   
  7. <input type = "submit" name = "submit" value="Calculate">   
  8. </form>   
  9. </body>   
  10. </html>  
  11. <?php   
  12. if(isset($_POST['submit']))  
  13.     {   
  14. $width = $_POST['width'];   
  15. $length = $_POST['length'];   
  16. $area = $width*$length;   
  17. echo "The area of a rectangle with $width x $length is $area";   
  18. }   
  19. ?>   

Output:

Comments