
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP hypot() Function
Definition and Usage
The hypot() function calculates length of hypotenus of a right angled triangle. Hypoteneuse is calculated as per following formula −
h=sqrt(x2+y2) where x and y are other two sides of a right angled triangle
For example, if x=3 and y=4, hypot(x,y)=5 which is equal to sqrt(32+42) = sqrt(25) =5
This function always returns a float.
Syntax
hypot ( float $x , float $y ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
x one side of right angled triangle |
2 |
y other side of right angled triangle |
Return Values
PHP hypot() function returns length of hypotenuse of a right angled triangle with given values of x and y
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example computes hypotenuse of a right angle triangle with sides 3 and 4−
<?php $x = 3; $y = 4; echo "hypot(" . $x . "," . $y . ") = " . hypot($x, $y); ?>
Output
This returns largest integer−
hypot(3,4) = 5
Example
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) ."
"; echo "Hypotenuse calculated by Pythogoras equation = " . sqrt(pow($x,2)+pow($y,2)); ?>
Output
This returns following output−
hypot(3,4) = 5 Hypotenuse calculated by Pythogoras equation = 5