find the area of a rectangle in php

To find the area of a rectangle in PHP, we need to multiply its length and width. Here's a code snippet that takes in the length and width of a rectangle and returns its area:

main.php
<?php
function calculateRectangleArea($length, $width){
    $area = $length * $width;
    return $area;
}

// Sample usage
$length = 10;
$width = 5;
$area = calculateRectangleArea($length, $width);
echo "The area of the rectangle with length $length and width $width is $area";
?>
281 chars
13 lines

In this code, we define a function calculateRectangleArea that takes in two parameters - length and width. We then calculate the area of the rectangle by multiplying the length and width and return the result.

At the bottom of the code, we set some sample values for length and width, call the calculateRectangleArea function with these values, and output the result. The output will be:

main.php
The area of the rectangle with length 10 and width 5 is 50
59 chars
2 lines

related categories

gistlibby LogSnag