本文整理汇总了PHP中Rectangle::area方法的典型用法代码示例。如果您正苦于以下问题:PHP Rectangle::area方法的具体用法?PHP Rectangle::area怎么用?PHP Rectangle::area使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rectangle
的用法示例。
在下文中一共展示了Rectangle::area方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: areaVerifier
function areaVerifier(Rectangle $r)
{
$r->setWidth(5);
$r->setHeight(4);
if ($r->area() != 20) {
return false;
}
return true;
}
示例2: Rectangle
<?php
require_once "rectangle.php";
require_once "square.php";
$rect1 = new Rectangle(2, 7);
echo $rect1->area();
echo "\n";
echo $rect1->perimeter();
echo "\n";
$rect2 = new Rectangle(3, 4);
echo $rect2->area();
echo "\n";
echo $rect2->perimeter();
echo "\n";
$square1 = new Square(2);
echo $square1->area();
echo "\n";
echo $square1->perimeter();
echo "\n";
$square1 = new Square(3);
echo $square1->area();
echo "\n";
echo $square1->perimeter();
echo "\n";
?>
?>
示例3: Rectangle
<?php
require_once 'square.php';
$rectangle = new Rectangle(20, 40);
echo 'The area of this rectangle is ' . $rectangle->area() . PHP_EOL;
$square = new Square(20);
echo 'The perimeter of this square is ' . $square->perimeter() . PHP_EOL;
示例4: 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();
示例5: Rectangle
<!-- shapes_test.php -->
<!-- 9.2.1 -->
<?php
require_once 'square.php';
// use this to run rectangle
$shape = new Rectangle(11, 39);
echo 'Area of Rectangle = ' . $shape->area() . PHP_EOL;
$square = new Square(2, 2);
echo 'Perimiter of square = ' . $square->Perimeter();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>shapes_test.php</title>
</head>
<body>
<h1> shapes_test.php | 9.2.1</h1>
<script>
console.log("INCLUDED: shapes_test.php")
</script>
</body>
</html>
示例6: Rectangle
<?php
require_once 'rectangle.php';
require_once 'square.php';
// Test your new class by creating an instance of Rectangle with various heights and widths.
$rekt_one = new Rectangle(7, 14);
$rekt_two = new Rectangle('5', '10');
$rekt_three = new Rectangle(33.33, 66.66);
$square_one = new Square(4);
// Calling the area method should correctly display the product of height and width.
var_dump($rekt_one->area());
var_dump($rekt_one->perimeter());
// var_dump($rekt_two->area());
// var_dump($rekt_three->area());
var_dump($square_one->perimeter());
var_dump($square_one->area());
示例7: Rectangle
<?php
require_once "rectangle.php";
require_once "square.php";
$rectangle = new Rectangle(4, 8);
$square = new Square(41);
echo $rectangle->area() . PHP_EOL;
echo $rectangle->perimeter() . PHP_EOL;
echo $square->area() . PHP_EOL;
echo $square->perimeter() . PHP_EOL;
示例8: Square
<?php
require_once "rectangle.php";
require_once "square.php";
$squr = new Square(10, 30);
$area = $squr->equalarea() . " sq.";
echo $area . PHP_EOL;
$perimeter = $squr->perimeter() . " long.";
echo $perimeter . PHP_EOL;
$rect = new Rectangle(10, 30);
$area = $rect->area() . " sq.";
echo $area . PHP_EOL;
$perimeter = $rect->perimeter() . " long.";
echo $perimeter . PHP_EOL;
示例9: 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;