The hypot() function calculates the hypotenuse of a right-angle triangle.
PHP hypot() Function has the following syntax.
hypot(x,y);
Parameter | IsRequired | Description |
---|---|---|
x | Required. | Length of first side |
y | Required. | Length of second side |
Item | Description |
---|---|
Return Value | The length of the hypotenuse |
Return Type | Float |
This function is equivalent to sqrt(x*x + y*y).
Calculate the hypotenuse of different right-angle triangles:
<?php
echo hypot(3,4) . "\n";
echo hypot(4,6) . "\n";
echo hypot(1,3) . "\n";
echo sqrt(3*3+4*4);
?>
The code above generates the following result.