<?Php
echo hypot(4,3); // Output is 5
echo "<br>";
echo hypot(2,3); // Output 3.605551275464
echo "<br>";
echo hypot(4,5); // Output 6.4031242374328
echo "<br>";
echo hypot(8,10); // Output is 12.806248474866
echo "<br>";
echo hypot(12,13); // Output is 17.691806012954
?>
Syntax
float hypot ( float $x , float $y )
| Parameter | DESCRIPTION |
|---|---|
| $x | Required : Length of first side. |
| $x | Required : Length of second side. |
echo round(hypot(9,10),2); // Output is 13.45
$a = 3;
$b = 4;
echo hypot($a, $b); // Output: 5 (Pythagorean theorem: sqrt(3^2 + 4^2))
$a = -3;
$b = 4;
echo hypot($a, $b); // Output: 5 (Negative values are squared, so the result is positive)
These examples demonstrate practical uses of `hypot()` for calculating hypotenuse and working with both positive and negative values.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.