Example 1 — Find the longest side
Calculate the hypotenuse for a few right triangles.
<?php
echo hypot(3, 4) . PHP_EOL;
echo hypot(5, 12) . PHP_EOL;
echo round(hypot(1, 1), 4) . PHP_EOL; How It Works
- For sides 3 and 4, 9 + 16 = 25 and the square root of 25 is 5.
- For sides 5 and 12, 25 + 144 = 169 and the square root is 13.
- For sides 1 and 1, the result is the square root of 2, about 1.4142.
- round() keeps the last result short.

