本文整理汇总了PHP中Rectangle::getPerimeter方法的典型用法代码示例。如果您正苦于以下问题:PHP Rectangle::getPerimeter方法的具体用法?PHP Rectangle::getPerimeter怎么用?PHP Rectangle::getPerimeter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rectangle
的用法示例。
在下文中一共展示了Rectangle::getPerimeter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPerimeter
{
return $width * $height;
}
public function getPerimeter($width, $height)
{
return $width + $height;
}
public function isSquare()
{
return $this->width == $this->height;
}
}
$width = 160;
$height = 75;
echo "<h2>With a width of {$width} and a height of {$height}...</h2>";
$r = new Rectangle($width, $height);
echo '<p>The area of the rectangle is ' . $r->getArea($width, $height) . '</p>';
echo '<p>The perimeter of the rectangle is ' . $r->getPerimeter($width, $height) . '</p>';
echo '<p>This rectangle is ';
if ($r->isSquare()) {
echo 'also';
} else {
echo 'not';
}
echo ' a square.</p>';
?>
</p>
</body>
</html>
示例2: getPerimeter
}
public function getPerimeter()
{
return $this->width * 2 + $this->height * 2;
}
public function isSquare()
{
if ($this->width == $this->height) {
return true;
}
}
}
$width = 160;
$height = 75;
echo "<h2>With a width of {$width} and a height of {$height}...</h2>";
$r = new Rectangle($width, $height);
echo '<p>The area of the rectangle is ' . $r->getArea() . '</p>';
echo '<p>The perimeter of the rectangle is ' . $r->getPerimeter() . '</p>';
echo '<p>This rectangle is ';
if ($r->isSquare()) {
echo 'also';
} else {
echo 'not';
}
echo ' a square.</p>';
?>
</p>
</body>
</html>
示例3: Rectangle
<?php
// PHP exercise about extending classes from a parent class. Rectangle is the parent class.
// Square is the child class extending off of Rectangle.
// This file runs in the command line.
// Because Square.php requires Rectangle.php, this file has access to both.
require_once 'Square.php';
$rectangle = new Rectangle(5, 10);
echo 'Rectangle area: ' . $rectangle->getArea() . PHP_EOL;
echo 'Rectangle perimeter: ' . $rectangle->getPerimeter() . PHP_EOL;
$square = new Square(9);
echo 'Square area: ' . $square->getArea() . PHP_EOL;
echo 'Square perimeter: ' . $square->getPerimeter() . PHP_EOL;
示例4: getArea
宽度:<input type="text" name="width" > <br/>
高度:<input type="text" name="height" > <br/>
<input type="submit" name="btn" value="计算">
</form>
</body>
</html>
<?php
include 'file_7_extraTraining.php';
class Rectangle extends Shape
{
private $width, $height;
function __construct($width, $height)
{
$this->width = $width;
$this->height = $height;
}
function getArea()
{
return $this->width * $this->height;
}
function getPerimeter()
{
return 2 * $this->width + 2 * $this->height;
}
}
if (isset($_POST["btn"])) {
$rect1 = new Rectangle($_POST["width"], $_POST["height"]);
echo "矩形的周长:" . $rect1->getPerimeter() . "<br/>";
echo "矩形的面积:" . $rect1->getArea() . "<br/>";
}