3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = [1, 2]; $b = [2, 4]; $p = [4, 3]; function vector_2d(array $v1, array $v2) { return [$v2[0] - $v1[0], $v2[1] - $v1[1]]; } function dot_product(array $v1, array $v2) { return $v1[0]*$v2[0] + $v1[1]*$v2[1]; } function modulus(array $v) { return sqrt($v[0]**2 + $v[1]**2); } $pa = vector_2d($p, $a); $ab = vector_2d($a, $b); $mpa = modulus($pa); $mab = modulus($ab); $theta = acos(dot_product($pa, $ab)/($mpa*$mab)); $perp_dist = $mpa*sin($theta); echo $perp_dist;
based on luPI6
Output for 5.6.0 - 7.3.0beta1
2.2360679774998
Output for 5.5.0 - 5.5.35
Parse error: syntax error, unexpected '*' in /in/bMI5L on line 17
Process exited with code 255.