PHP 矩形的面积
矩形的面积通过数学公式计算得出,
Length ∗ Breadth = Area
逻辑:
- 取两个变量。
- 将它们相乘。
PHP中的矩形面积
计算长为14,宽为12的矩形面积的程序如下所示。
示例:
<?php
length = 14;width = 12;
echo "area of rectangle is length *width= " . (length *width) . "<br />";
?>
输出:
使用PHP计算矩形面积的表单
显示通过在表单中插入值来计算矩形面积的程序。
示例:
<html>
<body>
<form method = "post">
Width: <input type="number" name="width">
<br><br>
Length: <input type="number" name="length"> <br>
<input type = "submit" name = "submit" value="Calculate">
</form>
</body>
</html>
<?php
if(isset(_POST['submit']))
{width = _POST['width'];length = _POST['length'];area = width*length;
echo "The area of a rectangle with width xlength is $area";
}
?>
输出: