本文整理汇总了PHP中Rectangle::getHeight方法的典型用法代码示例。如果您正苦于以下问题:PHP Rectangle::getHeight方法的具体用法?PHP Rectangle::getHeight怎么用?PHP Rectangle::getHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rectangle
的用法示例。
在下文中一共展示了Rectangle::getHeight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setHeight
$this->setWidth($width);
}
protected function setHeight($height)
{
$this->height = $height;
}
protected function setWidth($width)
{
$this->width = $width;
}
protected function getHeight()
{
return $this->height;
}
protected function getWidth()
{
return $this->width;
}
public function area()
{
return $this->getHeight() * $this->getWidth();
}
public function perimeter()
{
return $this->getHeight() * 2 + $this->getWidth() * 2;
}
}
$rectangle = new Rectangle(10, 10);
echo $rectangle->area();
echo $rectangle->getHeight();
echo $rectangle->getWidth();
示例2: isInner
/**
* Определяет, вложен ли текущий прямоугольник в заданный.
*
* @param Rectangle $rect
* @return type
*/
public function isInner(Rectangle $rect)
{
return $this->getTop() >= 0 && $this->getLeft() >= 0 && $this->getBottom() <= $rect->getHeight() && $this->getRight() <= $rect->getWidth();
}
示例3: Rectangle
<?php
require_once 'rectangle.php';
require_once 'square.php';
$rectangle = new Rectangle(10, 10);
echo $rectangle->area() . PHP_EOL;
echo "The area of a rectangle with height of {$rectangle->getHeight()} and width of {$rectangle->getWidth()} is {$rectangle->area()} " . PHP_EOL;
echo "The perimeter of a rectangle with height of {$rectangle->getHeight} and width of {$rectangle->getWidth()} is {$rectangle->perimeter()} " . PHP_EOL;
// $square = new Square(5);
// echo "The area of a square with height of {$square->height} is {$square->area()} " . PHP_EOL;
// echo "The perimeter of a square with height of {$square->height} is {$square->perimeter()} " . PHP_EOL;