3v4l.org

run code in 300+ PHP versions simultaneously
<?php $latitude = '1234'; $longitude = '4567'; $items = [ ['name' => 'me', 'latitude' => '1234', 'longitude' =>'4567'], ['name' => 'you', 'latitude' => '2345', 'longitude' =>'5678'] ]; $ref = array($latitude, $longitude); $distances = array_map(function($item) use($ref) { $a = array_slice($item, -2); return distance($a, $ref); }, $items); asort($distances); function distance($a, $b) { list($lat1, $lon1) = $a; list($lat2, $lon2) = $b; $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; return $miles; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8Ig0
function name:  (null)
number of ops:  17
compiled vars:  !0 = $latitude, !1 = $longitude, !2 = $items, !3 = $ref, !4 = $distances
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '1234'
    5     1        ASSIGN                                                   !1, '4567'
    7     2        ASSIGN                                                   !2, <array>
   11     3        INIT_ARRAY                                       ~8      !0
          4        ADD_ARRAY_ELEMENT                                ~8      !1
          5        ASSIGN                                                   !3, ~8
   13     6        INIT_FCALL                                               'array_map'
          7        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
          8        BIND_LEXICAL                                             ~10, !3
   16     9        SEND_VAL                                                 ~10
         10        SEND_VAR                                                 !2
   13    11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !4, $11
   18    13        INIT_FCALL                                               'asort'
         14        SEND_REF                                                 !4
         15        DO_ICALL                                                 
   32    16      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8Ig0
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $item, !1 = $ref, !2 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   14     2        INIT_FCALL                                               'array_slice'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -2
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
   15     7        INIT_FCALL_BY_NAME                                       'distance'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $5      
         11      > RETURN                                                   $5
   16    12*     > RETURN                                                   null

End of Dynamic Function 0

Function distance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8Ig0
function name:  distance
number of ops:  64
compiled vars:  !0 = $a, !1 = $b, !2 = $lat1, !3 = $lon1, !4 = $lat2, !5 = $lon2, !6 = $theta, !7 = $dist, !8 = $miles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        QM_ASSIGN                                        ~9      !0
          3        FETCH_LIST_R                                     $10     ~9, 0
          4        ASSIGN                                                   !2, $10
          5        FETCH_LIST_R                                     $12     ~9, 1
          6        ASSIGN                                                   !3, $12
          7        FREE                                                     ~9
   24     8        QM_ASSIGN                                        ~14     !1
          9        FETCH_LIST_R                                     $15     ~14, 0
         10        ASSIGN                                                   !4, $15
         11        FETCH_LIST_R                                     $17     ~14, 1
         12        ASSIGN                                                   !5, $17
         13        FREE                                                     ~14
   26    14        SUB                                              ~19     !3, !5
         15        ASSIGN                                                   !6, ~19
   27    16        INIT_FCALL                                               'sin'
         17        INIT_FCALL                                               'deg2rad'
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $21     
         20        SEND_VAR                                                 $21
         21        DO_ICALL                                         $22     
         22        INIT_FCALL                                               'sin'
         23        INIT_FCALL                                               'deg2rad'
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $23     
         26        SEND_VAR                                                 $23
         27        DO_ICALL                                         $24     
         28        MUL                                              ~25     $22, $24
         29        INIT_FCALL                                               'cos'
         30        INIT_FCALL                                               'deg2rad'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                         $26     
         33        SEND_VAR                                                 $26
         34        DO_ICALL                                         $27     
         35        INIT_FCALL                                               'cos'
         36        INIT_FCALL                                               'deg2rad'
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                         $28     
         39        SEND_VAR                                                 $28
         40        DO_ICALL                                         $29     
         41        MUL                                              ~30     $27, $29
         42        INIT_FCALL                                               'cos'
         43        INIT_FCALL                                               'deg2rad'
         44        SEND_VAR                                                 !6
         45        DO_ICALL                                         $31     
         46        SEND_VAR                                                 $31
         47        DO_ICALL                                         $32     
         48        MUL                                              ~33     $32, ~30
         49        ADD                                              ~34     ~25, ~33
         50        ASSIGN                                                   !7, ~34
   28    51        INIT_FCALL                                               'acos'
         52        SEND_VAR                                                 !7
         53        DO_ICALL                                         $36     
         54        ASSIGN                                                   !7, $36
   29    55        INIT_FCALL                                               'rad2deg'
         56        SEND_VAR                                                 !7
         57        DO_ICALL                                         $38     
         58        ASSIGN                                                   !7, $38
   30    59        MUL                                              ~40     !7, 60
         60        MUL                                              ~41     ~40, 1.1515
         61        ASSIGN                                                   !8, ~41
   31    62      > RETURN                                                   !8
   32    63*     > RETURN                                                   null

End of function distance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.49 ms | 1014 KiB | 21 Q