Create a PHP script that calculates and displays the area of a rectangle given its length and width.

function calculateRectangleArea($length, $width) {
    return $length * $width;

$rectangleLength = 8;
$rectangleWidth = 5;

$area = calculateRectangleArea($rectangleLength, $rectangleWidth);

echo "The area of the rectangle is: $area square units";
  • The script defines a function calculateRectangleArea that takes the length and width of a rectangle and returns its area.
  • The area of a rectangle is calculated by multiplying its length and width.
  • The script then calls the function with sample values ($rectangleLength and $rectangleWidth) and prints the result.

Post your Answer