php
  1. php-area-of-rectangle

PHP Area of Rectangle

Syntax

float rectangle_area(float $length, float $width)

Example

function rectangle_area($length, $width) {
    return $length * $width;
}
echo "The area of rectangle with length 5 and width 3 is " . rectangle_area(5, 3);

Output

The area of rectangle with length 5 and width 3 is 15

Explanation

The given function accepts two parameters: length and width of the rectangle as float values. It then returns the area of the rectangle which is calculated by multiplying length and width of the rectangle.

Use

This function can be used in various PHP projects where we need to calculate the area of a rectangle. This can be helpful in web development projects, geometry related applications, and more.

Important Points

  • The length and width parameters of the function should be passed as float values only.
  • The input values for length and width should not be negative.
  • The result of the function will be in float format.

Summary

In this tutorial, we learned about the PHP function to calculate the area of a rectangle. We discussed the syntax of the function, explained an example, and shared its output. The tutorial also explained the use case and important points about the function.

Published on: