3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Warning: Undefined variable $p in /in/luPI6 on line 15 Warning: Undefined variable $a in /in/luPI6 on line 15 Fatal error: Uncaught TypeError: vector_2d(): Argument #1 ($v1) must be of type array, null given, called in /in/luPI6 on line 15 and defined in /in/luPI6:3 Stack trace: #0 /in/luPI6(15): vector_2d(NULL, NULL) #1 {main} thrown in /in/luPI6 on line 3
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.31, 7.4.0 - 7.4.33
Notice: Undefined variable: p in /in/luPI6 on line 15 Notice: Undefined variable: a in /in/luPI6 on line 15 Fatal error: Uncaught TypeError: Argument 1 passed to vector_2d() must be of the type array, null given, called in /in/luPI6 on line 15 and defined in /in/luPI6:3 Stack trace: #0 /in/luPI6(15): vector_2d(NULL, NULL) #1 {main} thrown in /in/luPI6 on line 3
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught TypeError: Argument 1 passed to vector_2d() must be of the type array, null given, called in /in/luPI6 on line 15 and defined in /in/luPI6:3 Stack trace: #0 /in/luPI6(15): vector_2d(NULL, NULL) #1 {main} thrown in /in/luPI6 on line 3
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Notice: Undefined variable: p in /in/luPI6 on line 15 Notice: Undefined variable: a in /in/luPI6 on line 15 Catchable fatal error: Argument 1 passed to vector_2d() must be of the type array, null given, called in /in/luPI6 on line 15 and defined in /in/luPI6 on line 3
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '*' in /in/luPI6 on line 12
Process exited with code 255.

preferences:
215.31 ms | 401 KiB | 332 Q