hypot()函数计算直角三角形的斜边长度。斜边的计算公式如下:
h=sqrt(x2+y2),其中x和y是直角三角形的另外两条边
例如,如果x=3,y=4,那么hypot(x,y)=5,即sqrt(32+42) = sqrt(25) =5
该函数总是返回一个浮点数。
立即学习“PHP免费学习笔记(深入)”;
hypot ( float $x , float $y ) : float
序号 | 参数和说明 |
---|---|
1 |
x 直角三角形的一边 |
2 |
y 直角三角形的另一边 |
PHP hypot() 函数返回给定 x 和 y 值的直角三角形的斜边长度
此函数在 PHP 版本 4.x、PHP 5.x 和 PHP 7.x 中可用。
在线演示
以下示例计算具有边长为 3 和 4 的直角三角形的斜边长度−
<?php $x = 3; $y = 4; echo "hypot(" . $x . "," . $y . ") = " . hypot($x, $y); ?>
This returns largest integer−
hypot(3,4) = 5
Live Demo
Return value of hypot(x,y) function is equal to sqrt(x*x+y*y) as per pythogoras theorem. Following example confirms it−
<?php $x = 3; $y = 4; echo "hypot(" . $x . "," . $y . ") = " . hypot($x, $y) ."</p><p>"; echo "Hypotenuse calculated by Pythogoras equation = " . sqrt(pow($x,2)+pow($y,2)); ?>
这将返回以下输出−
hypot(3,4) = 5 Hypotenuse calculated by Pythogoras equation = 5
以上就是PHP hypot() 函数的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号