3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); $distance = sqrt(( $p1 + $p2 )); /** $points = [$p1, $p2]; $distance = array_sum($points); $distance = sqrt(($x1 - $x2) + ($y1 - $y2))**2; */ //$distance = hypot($p1, $p2); return $distance; }
based on I4HcN
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
y1 is : 4 y2 is : 9 x1 is : 2 x2 is : 26 distance is : NAN