3v4l.org

run code in 300+ PHP versions simultaneously
<?php $d = distance([2,4], [26,9]); echo 'distance is : ' .$d; function distance( $p1=array(), $p2=array()) { $x1 = $p1[0]; $x2 = $p2[0]; $y1 = $p1[1]; $y2 = $p2[1]; echo "y1 is : $y1\n"; echo "y2 is : $y2\n"; echo "x1 is : $x1\n"; echo "x2 is : $x2\n"; /** $p1 = ($x1 - $x2); // $p2 = ($y1 - $y2); // $points = [$p1, $p2]; //$distance = array_sum($points); // $distance = sqrt(($x1 - $x2) + ($y1 - $y2))**2; */ $distance = hypot($p1, $p2); return $distance; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
y1 is : 4 y2 is : 9 x1 is : 2 x2 is : 26 Fatal error: Uncaught TypeError: hypot(): Argument #1 ($x) must be of type float, array given in /in/NUjFV:32 Stack trace: #0 /in/NUjFV(32): hypot(Array, Array) #1 /in/NUjFV(3): distance(Array, Array) #2 {main} thrown in /in/NUjFV on line 32
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 y1 is : 4 y2 is : 9 x1 is : 2 x2 is : 26 Fatal error: Uncaught TypeError: hypot(): Argument #1 ($x) must be of type float, array given in /in/NUjFV:32 Stack trace: #0 /in/NUjFV(32): hypot(Array, Array) #1 /in/NUjFV(3): distance(Array, Array) #2 {main} thrown in /in/NUjFV on line 32
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
y1 is : 4 y2 is : 9 x1 is : 2 x2 is : 26 Warning: hypot() expects parameter 1 to be float, array given in /in/NUjFV on line 32 distance is :
Output for 5.6.0 - 5.6.40
y1 is : 4 y2 is : 9 x1 is : 2 x2 is : 26 Warning: hypot() expects parameter 1 to be double, array given in /in/NUjFV on line 32 distance is :

preferences:
228.28 ms | 401 KiB | 291 Q