3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** *求两个已知经纬度之间的距离,单位为米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位米 *@author www.phpernote.com **/ function getdistance($lng1,$lat1,$lng2,$lat2){ //将角度转为狐度 $radLat1=deg2rad($lat1);//deg2rad()函数将角度转换为弧度 $radLat2=deg2rad($lat2); $radLng1=deg2rad($lng1); $radLng2=deg2rad($lng2); $a=$radLat1-$radLat2; $b=$radLng1-$radLng2; $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000; return $s; } echo getdistance(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998); function calculateSignDistance($longitude1, $latitude1, $longitude2, $latitude2) { $lat1 = ($latitude1 * pi() ) / 180; $lng1 = ($longitude1 * pi() ) / 180; $lat2 = ($longitude2 * pi() ) / 180; $lng2 = ($latitude2 * pi() ) / 180; $calcLongitude = $lng2 - $lng1; $calcLatitude = $lat2 - $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(min(1, sqrt($stepOne))); return $calculatedDistance = 6370996.81 * $stepTwo; } echo "\n"; echo calculateSignDistance(121.40233369999998,31.2014966,121.44552099999998,31.22323799999999); /** *求两个已知经纬度之间的距离,单位为千米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位千米 **/ function distance($lng1,$lat1,$lng2,$lat2)//根据经纬度计算距离 { //将角度转为弧度 $radLat1=deg2rad($lat1); $radLat2=deg2rad($lat2); $radLng1=deg2rad($lng1); $radLng2=deg2rad($lng2); $a=$radLat1-$radLat2;//两纬度之差,纬度<90 $b=$radLng1-$radLng2;//两经度之差纬度<180 $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000; return $s; } echo "\n"; echo distance(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998); /** * @desc 根据两点间的经纬度计算距离 * @param float $lat 纬度值 * @param float $lng 经度值 */ function getDistance3($lat1, $lng1, $lat2, $lng2) { $earthRadius = 6378137; //approximate radius of earth in meters /* Convert these degrees to radians to work with the formula */ $lat1 = ($lat1 * pi() ) / 180; $lng1 = ($lng1 * pi() ) / 180; $lat2 = ($lat2 * pi() ) / 180; $lng2 = ($lng2 * pi() ) / 180; /* Using the Haversine formula http://en.wikipedia.org/wiki/Haversine_formula calculate the distance */ $calcLongitude = $lng2 - $lng1; $calcLatitude = $lat2 - $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(min(1, sqrt($stepOne))); $calculatedDistance = $earthRadius * $stepTwo; return round($calculatedDistance); } echo "\n"; echo getDistance3(121.40233369999998,31.2014966,121.44552099999998,31.22323799999999);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WsLOE
function name:  (null)
number of ops:  32
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'getdistance'
          1        SEND_VAL                                                 31.2015
          2        SEND_VAL                                                 121.402
          3        SEND_VAL                                                 31.2232
          4        SEND_VAL                                                 121.446
          5        DO_FCALL                                      0  $0      
          6        ECHO                                                     $0
   34     7        ECHO                                                     '%0A'
   35     8        INIT_FCALL                                               'calculatesigndistance'
          9        SEND_VAL                                                 121.402
         10        SEND_VAL                                                 31.2015
         11        SEND_VAL                                                 121.446
         12        SEND_VAL                                                 31.2232
         13        DO_FCALL                                      0  $1      
         14        ECHO                                                     $1
   55    15        ECHO                                                     '%0A'
   56    16        INIT_FCALL                                               'distance'
         17        SEND_VAL                                                 31.2015
         18        SEND_VAL                                                 121.402
         19        SEND_VAL                                                 31.2232
         20        SEND_VAL                                                 121.446
         21        DO_FCALL                                      0  $2      
         22        ECHO                                                     $2
   95    23        ECHO                                                     '%0A'
   96    24        INIT_FCALL                                               'getdistance3'
         25        SEND_VAL                                                 121.402
         26        SEND_VAL                                                 31.2015
         27        SEND_VAL                                                 121.446
         28        SEND_VAL                                                 31.2232
         29        DO_FCALL                                      0  $3      
         30        ECHO                                                     $3
         31      > RETURN                                                   1

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

End of function getdistance

Function calculatesigndistance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WsLOE
function name:  calculateSignDistance
number of ops:  70
compiled vars:  !0 = $longitude1, !1 = $latitude1, !2 = $longitude2, !3 = $latitude2, !4 = $lat1, !5 = $lng1, !6 = $lat2, !7 = $lng2, !8 = $calcLongitude, !9 = $calcLatitude, !10 = $stepOne, !11 = $stepTwo, !12 = $calculatedDistance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   24     4        INIT_FCALL                                               'pi'
          5        DO_ICALL                                         $13     
          6        MUL                                              ~14     !1, $13
          7        DIV                                              ~15     ~14, 180
          8        ASSIGN                                                   !4, ~15
   25     9        INIT_FCALL                                               'pi'
         10        DO_ICALL                                         $17     
         11        MUL                                              ~18     !0, $17
         12        DIV                                              ~19     ~18, 180
         13        ASSIGN                                                   !5, ~19
   26    14        INIT_FCALL                                               'pi'
         15        DO_ICALL                                         $21     
         16        MUL                                              ~22     !2, $21
         17        DIV                                              ~23     ~22, 180
         18        ASSIGN                                                   !6, ~23
   27    19        INIT_FCALL                                               'pi'
         20        DO_ICALL                                         $25     
         21        MUL                                              ~26     !3, $25
         22        DIV                                              ~27     ~26, 180
         23        ASSIGN                                                   !7, ~27
   28    24        SUB                                              ~29     !7, !5
         25        ASSIGN                                                   !8, ~29
   29    26        SUB                                              ~31     !6, !4
         27        ASSIGN                                                   !9, ~31
   30    28        INIT_FCALL                                               'pow'
         29        INIT_FCALL                                               'sin'
         30        DIV                                              ~33     !9, 2
         31        SEND_VAL                                                 ~33
         32        DO_ICALL                                         $34     
         33        SEND_VAR                                                 $34
         34        SEND_VAL                                                 2
         35        DO_ICALL                                         $35     
         36        INIT_FCALL                                               'cos'
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                         $36     
         39        INIT_FCALL                                               'cos'
         40        SEND_VAR                                                 !6
         41        DO_ICALL                                         $37     
         42        MUL                                              ~38     $36, $37
         43        INIT_FCALL                                               'pow'
         44        INIT_FCALL                                               'sin'
         45        DIV                                              ~39     !8, 2
         46        SEND_VAL                                                 ~39
         47        DO_ICALL                                         $40     
         48        SEND_VAR                                                 $40
         49        SEND_VAL                                                 2
         50        DO_ICALL                                         $41     
         51        MUL                                              ~42     $41, ~38
         52        ADD                                              ~43     $35, ~42
         53        ASSIGN                                                   !10, ~43
   31    54        INIT_FCALL                                               'asin'
         55        INIT_FCALL                                               'min'
         56        SEND_VAL                                                 1
         57        INIT_FCALL                                               'sqrt'
         58        SEND_VAR                                                 !10
         59        DO_ICALL                                         $45     
         60        SEND_VAR                                                 $45
         61        DO_ICALL                                         $46     
         62        SEND_VAR                                                 $46
         63        DO_ICALL                                         $47     
         64        MUL                                              ~48     $47, 2
         65        ASSIGN                                                   !11, ~48
   32    66        MUL                                              ~50     !11, 6.371e+6
         67        ASSIGN                                           ~51     !12, ~50
         68      > RETURN                                                   ~51
   33    69*     > RETURN                                                   null

End of function calculatesigndistance

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

End of function distance

Function getdistance3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WsLOE
function name:  getDistance3
number of ops:  74
compiled vars:  !0 = $lat1, !1 = $lng1, !2 = $lat2, !3 = $lng2, !4 = $earthRadius, !5 = $calcLongitude, !6 = $calcLatitude, !7 = $stepOne, !8 = $stepTwo, !9 = $calculatedDistance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   66     4        ASSIGN                                                   !4, 6378137
   73     5        INIT_FCALL                                               'pi'
          6        DO_ICALL                                         $11     
          7        MUL                                              ~12     !0, $11
          8        DIV                                              ~13     ~12, 180
          9        ASSIGN                                                   !0, ~13
   74    10        INIT_FCALL                                               'pi'
         11        DO_ICALL                                         $15     
         12        MUL                                              ~16     !1, $15
         13        DIV                                              ~17     ~16, 180
         14        ASSIGN                                                   !1, ~17
   76    15        INIT_FCALL                                               'pi'
         16        DO_ICALL                                         $19     
         17        MUL                                              ~20     !2, $19
         18        DIV                                              ~21     ~20, 180
         19        ASSIGN                                                   !2, ~21
   77    20        INIT_FCALL                                               'pi'
         21        DO_ICALL                                         $23     
         22        MUL                                              ~24     !3, $23
         23        DIV                                              ~25     ~24, 180
         24        ASSIGN                                                   !3, ~25
   88    25        SUB                                              ~27     !3, !1
         26        ASSIGN                                                   !5, ~27
   89    27        SUB                                              ~29     !2, !0
         28        ASSIGN                                                   !6, ~29
   90    29        INIT_FCALL                                               'pow'
         30        INIT_FCALL                                               'sin'
         31        DIV                                              ~31     !6, 2
         32        SEND_VAL                                                 ~31
         33        DO_ICALL                                         $32     
         34        SEND_VAR                                                 $32
         35        SEND_VAL                                                 2
         36        DO_ICALL                                         $33     
         37        INIT_FCALL                                               'cos'
         38        SEND_VAR                                                 !0
         39        DO_ICALL                                         $34     
         40        INIT_FCALL                                               'cos'
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                         $35     
         43        MUL                                              ~36     $34, $35
         44        INIT_FCALL                                               'pow'
         45        INIT_FCALL                                               'sin'
         46        DIV                                              ~37     !5, 2
         47        SEND_VAL                                                 ~37
         48        DO_ICALL                                         $38     
         49        SEND_VAR                                                 $38
         50        SEND_VAL                                                 2
         51        DO_ICALL                                         $39     
         52        MUL                                              ~40     $39, ~36
         53        ADD                                              ~41     $33, ~40
         54        ASSIGN                                                   !7, ~41
         55        INIT_FCALL                                               'asin'
         56        INIT_FCALL                                               'min'
         57        SEND_VAL                                                 1
         58        INIT_FCALL                                               'sqrt'
         59        SEND_VAR                                                 !7
         60        DO_ICALL                                         $43     
         61        SEND_VAR                                                 $43
         62        DO_ICALL                                         $44     
         63        SEND_VAR                                                 $44
         64        DO_ICALL                                         $45     
         65        MUL                                              ~46     $45, 2
         66        ASSIGN                                                   !8, ~46
   91    67        MUL                                              ~48     !4, !8
         68        ASSIGN                                                   !9, ~48
   93    69        INIT_FCALL                                               'round'
         70        SEND_VAR                                                 !9
         71        DO_ICALL                                         $50     
         72      > RETURN                                                   $50
   94    73*     > RETURN                                                   null

End of function getdistance3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.56 ms | 1117 KiB | 26 Q