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;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bMI5L
function name:  (null)
number of ops:  38
compiled vars:  !0 = $a, !1 = $b, !2 = $p, !3 = $pa, !4 = $ab, !5 = $mpa, !6 = $mab, !7 = $theta, !8 = $perp_dist
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
   20     3        INIT_FCALL                                               'vector_2d'
          4        SEND_VAR                                                 !2
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $12     
          7        ASSIGN                                                   !3, $12
   21     8        INIT_FCALL                                               'vector_2d'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $14     
         12        ASSIGN                                                   !4, $14
   23    13        INIT_FCALL                                               'modulus'
         14        SEND_VAR                                                 !3
         15        DO_FCALL                                      0  $16     
         16        ASSIGN                                                   !5, $16
   24    17        INIT_FCALL                                               'modulus'
         18        SEND_VAR                                                 !4
         19        DO_FCALL                                      0  $18     
         20        ASSIGN                                                   !6, $18
   26    21        INIT_FCALL                                               'acos'
         22        INIT_FCALL                                               'dot_product'
         23        SEND_VAR                                                 !3
         24        SEND_VAR                                                 !4
         25        DO_FCALL                                      0  $20     
         26        MUL                                              ~21     !5, !6
         27        DIV                                              ~22     $20, ~21
         28        SEND_VAL                                                 ~22
         29        DO_ICALL                                         $23     
         30        ASSIGN                                                   !7, $23
   28    31        INIT_FCALL                                               'sin'
         32        SEND_VAR                                                 !7
         33        DO_ICALL                                         $25     
         34        MUL                                              ~26     !5, $25
         35        ASSIGN                                                   !8, ~26
   30    36        ECHO                                                     !8
         37      > RETURN                                                   1

Function vector_2d:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bMI5L
function name:  vector_2d
number of ops:  12
compiled vars:  !0 = $v1, !1 = $v2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        FETCH_DIM_R                                      ~2      !1, 0
          3        FETCH_DIM_R                                      ~3      !0, 0
          4        SUB                                              ~4      ~2, ~3
          5        INIT_ARRAY                                       ~5      ~4
          6        FETCH_DIM_R                                      ~6      !1, 1
          7        FETCH_DIM_R                                      ~7      !0, 1
          8        SUB                                              ~8      ~6, ~7
          9        ADD_ARRAY_ELEMENT                                ~5      ~8
         10      > RETURN                                                   ~5
   10    11*     > RETURN                                                   null

End of function vector_2d

Function dot_product:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bMI5L
function name:  dot_product
number of ops:  11
compiled vars:  !0 = $v1, !1 = $v2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        FETCH_DIM_R                                      ~2      !0, 0
          3        FETCH_DIM_R                                      ~3      !1, 0
          4        MUL                                              ~4      ~2, ~3
          5        FETCH_DIM_R                                      ~5      !0, 1
          6        FETCH_DIM_R                                      ~6      !1, 1
          7        MUL                                              ~7      ~5, ~6
          8        ADD                                              ~8      ~4, ~7
          9      > RETURN                                                   ~8
   14    10*     > RETURN                                                   null

End of function dot_product

Function modulus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bMI5L
function name:  modulus
number of ops:  11
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'sqrt'
          2        FETCH_DIM_R                                      ~1      !0, 0
          3        POW                                              ~2      ~1, 2
          4        FETCH_DIM_R                                      ~3      !0, 1
          5        POW                                              ~4      ~3, 2
          6        ADD                                              ~5      ~2, ~4
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9      > RETURN                                                   $6
   18    10*     > RETURN                                                   null

End of function modulus

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
238.51 ms | 1403 KiB | 24 Q