当前位置: 首页>>代码示例>>PHP>>正文


PHP Rectangle::isSquare方法代码示例

本文整理汇总了PHP中Rectangle::isSquare方法的典型用法代码示例。如果您正苦于以下问题:PHP Rectangle::isSquare方法的具体用法?PHP Rectangle::isSquare怎么用?PHP Rectangle::isSquare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rectangle的用法示例。


在下文中一共展示了Rectangle::isSquare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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>
开发者ID:Code2Hire,项目名称:challenges-student-work,代码行数:31,代码来源:1_easy.php

示例2: function

<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Rectangle.php";
$app = new Silex\Application();
$app->get("/", function () {
    return "Home";
});
$app->get("/new_rectangle", function () {
    return "<!DOCTYPE html>\n        <html>\n        <head>\n            <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'>\n            <title>Make a rectangle!</title>\n        </head>\n        <body>\n            <div class='container'>\n                <h1>Geometry Checker</h1>\n                <p>Enter the dimensions of your rectangle to see if it's a square.</p>\n                <form action='/view_rectangle'>\n                    <div class='form-group'>\n                      <label for='length'>Enter the length:</label>\n                      <input id='length' name='length' class='form-control' type='number'>\n                    </div>\n                    <div class='form-group'>\n                      <label for='width'>Enter the width:</label>\n                      <input id='width' name='width' class='form-control' type='number'>\n                    </div>\n                    <button type='submit' class='btn-success'>Create</button>\n                </form>\n            </div>\n        </body>\n        </html>";
});
$app->get("/view_rectangle", function () {
    $my_rectangle = new Rectangle($_GET['length'], $_GET['width']);
    $area = $my_rectangle->getArea();
    if ($my_rectangle->isSquare()) {
        return "<h1>Congratulations! You made a square! Its area is {$area}.</h1>\n                    <a href='/new_rectangle'>Back!</a>";
    } else {
        return "<h1>Sorry! This isn't a square. Its area is {$area}.</h1>\n            <a href='/new_rectangle'>Back!</a>";
    }
});
return $app;
开发者ID:joekarasek,项目名称:epicodus-php-rectangle,代码行数:21,代码来源:app.php


注:本文中的Rectangle::isSquare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。