PHP hypot()

ChrisLarham's avatar
Published Jul 20, 2023
Contribute to Docs

The hypot() function returns the length of the hypotenuse of a 90-degree or “right-angle” triangle.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

$hypotenuse = hypot($length1, $length2);

Given a right-angle triangle with sides $length1 and $length2, the function returns the result of the following formula:

hypotenuse=length12+length22hypotenuse = \sqrt{length1^2 + length2^2}

The function accepts two float inputs and returns a value of type float.

Example

This example calculates the hypotenuse of a right-angle triangle with sides of length 6 and 8.

<?php
$hypotenuse = hypot(6, 8);
echo $hypotenuse;
?>

This example results in the following output:

10

Codebyte Example

This example returns the hypotenuse for a 90-degree triangle with sides of length 12 and 16:

Code
Output

All contributors

Contribute to Docs

Learn PHP on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours