3v4l.org

run code in 300+ PHP versions simultaneously
<?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;
Output for git.master, git.master_jit, rfc.property-hooks
2.2360679774998

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.12 ms | 401 KiB | 8 Q