3v4l.org

run code in 300+ PHP versions simultaneously
<?php /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: :*/ /*:: This routine calculates the distance between two points (given the :*/ /*:: latitude/longitude of those points). It is being used to calculate :*/ /*:: the distance between two locations using GeoDataSource(TM) Products :*/ /*:: :*/ /*:: Definitions: :*/ /*:: South latitudes are negative, east longitudes are positive :*/ /*:: :*/ /*:: Passed to function: :*/ /*:: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/ /*:: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/ /*:: unit = the unit you desire for results :*/ /*:: where: 'M' is statute miles :*/ /*:: 'K' is kilometers (default) :*/ /*:: 'N' is nautical miles :*/ /*:: Worldwide cities and other features databases with latitude longitude :*/ /*:: are available at http://www.geodatasource.com :*/ /*:: :*/ /*:: For enquiries, please contact sales@geodatasource.com :*/ /*:: :*/ /*:: Official Web site: http://www.geodatasource.com :*/ /*:: :*/ /*:: GeoDataSource.com (C) All Rights Reserved 2014 :*/ /*:: :*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ function distance($lat1, $lon1, $lat2, $lon2, $unit) { $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; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>"; echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>"; echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/seCYM
function name:  (null)
number of ops:  28
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                               'distance'
          1        SEND_VAL                                                 32.9697
          2        SEND_VAL                                                 -96.8032
          3        SEND_VAL                                                 29.4679
          4        SEND_VAL                                                 -98.5351
          5        SEND_VAL                                                 'M'
          6        DO_FCALL                                      0  $0      
          7        CONCAT                                           ~1      $0, '+Miles%3Cbr%3E'
          8        ECHO                                                     ~1
   48     9        INIT_FCALL                                               'distance'
         10        SEND_VAL                                                 32.9697
         11        SEND_VAL                                                 -96.8032
         12        SEND_VAL                                                 29.4679
         13        SEND_VAL                                                 -98.5351
         14        SEND_VAL                                                 'K'
         15        DO_FCALL                                      0  $2      
         16        CONCAT                                           ~3      $2, '+Kilometers%3Cbr%3E'
         17        ECHO                                                     ~3
   49    18        INIT_FCALL                                               'distance'
         19        SEND_VAL                                                 32.9697
         20        SEND_VAL                                                 -96.8032
         21        SEND_VAL                                                 29.4679
         22        SEND_VAL                                                 -98.5351
         23        SEND_VAL                                                 'N'
         24        DO_FCALL                                      0  $4      
         25        CONCAT                                           ~5      $4, '+Nautical+Miles%3Cbr%3E'
         26        ECHO                                                     ~5
   51    27      > RETURN                                                   1

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

End of function distance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.35 ms | 1407 KiB | 28 Q