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(sqrt($stepOne)); return 6378.137*1000 * $stepTwo; } echo "\n"; echo calculateSignDistance(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998); /** *求两个已知经纬度之间的距离,单位为千米 *@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 = $lng1-$lng2 ; $calcLatitude = $lat1-$lat2 ; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(sqrt($stepOne)); $calculatedDistance = $earthRadius * $stepTwo; return $calculatedDistance; } echo "\n"; echo getDistance3(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CssAh
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                                                 31.2015
         10        SEND_VAL                                                 121.402
         11        SEND_VAL                                                 31.2232
         12        SEND_VAL                                                 121.446
         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                                                 31.2015
         26        SEND_VAL                                                 121.402
         27        SEND_VAL                                                 31.2232
         28        SEND_VAL                                                 121.446
         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/CssAh
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/CssAh
function name:  calculateSignDistance
number of ops:  65
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
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                                         $12     
          6        MUL                                              ~13     !1, $12
          7        DIV                                              ~14     ~13, 180
          8        ASSIGN                                                   !4, ~14
   25     9        INIT_FCALL                                               'pi'
         10        DO_ICALL                                         $16     
         11        MUL                                              ~17     !0, $16
         12        DIV                                              ~18     ~17, 180
         13        ASSIGN                                                   !5, ~18
   26    14        INIT_FCALL                                               'pi'
         15        DO_ICALL                                         $20     
         16        MUL                                              ~21     !2, $20
         17        DIV                                              ~22     ~21, 180
         18        ASSIGN                                                   !6, ~22
   27    19        INIT_FCALL                                               'pi'
         20        DO_ICALL                                         $24     
         21        MUL                                              ~25     !3, $24
         22        DIV                                              ~26     ~25, 180
         23        ASSIGN                                                   !7, ~26
   28    24        SUB                                              ~28     !7, !5
         25        ASSIGN                                                   !8, ~28
   29    26        SUB                                              ~30     !6, !4
         27        ASSIGN                                                   !9, ~30
   30    28        INIT_FCALL                                               'pow'
         29        INIT_FCALL                                               'sin'
         30        DIV                                              ~32     !9, 2
         31        SEND_VAL                                                 ~32
         32        DO_ICALL                                         $33     
         33        SEND_VAR                                                 $33
         34        SEND_VAL                                                 2
         35        DO_ICALL                                         $34     
         36        INIT_FCALL                                               'cos'
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                         $35     
         39        INIT_FCALL                                               'cos'
         40        SEND_VAR                                                 !6
         41        DO_ICALL                                         $36     
         42        MUL                                              ~37     $35, $36
         43        INIT_FCALL                                               'pow'
         44        INIT_FCALL                                               'sin'
         45        DIV                                              ~38     !8, 2
         46        SEND_VAL                                                 ~38
         47        DO_ICALL                                         $39     
         48        SEND_VAR                                                 $39
         49        SEND_VAL                                                 2
         50        DO_ICALL                                         $40     
         51        MUL                                              ~41     $40, ~37
         52        ADD                                              ~42     $34, ~41
         53        ASSIGN                                                   !10, ~42
   31    54        INIT_FCALL                                               'asin'
         55        INIT_FCALL                                               'sqrt'
         56        SEND_VAR                                                 !10
         57        DO_ICALL                                         $44     
         58        SEND_VAR                                                 $44
         59        DO_ICALL                                         $45     
         60        MUL                                              ~46     $45, 2
         61        ASSIGN                                                   !11, ~46
   32    62        MUL                                              ~48     !11, 6.37814e+6
         63      > RETURN                                                   ~48
   33    64*     > 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/CssAh
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/CssAh
function name:  getDistance3
number of ops:  67
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     !1, !3
         26        ASSIGN                                                   !5, ~27
   89    27        SUB                                              ~29     !0, !2
         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                                               'sqrt'
         57        SEND_VAR                                                 !7
         58        DO_ICALL                                         $43     
         59        SEND_VAR                                                 $43
         60        DO_ICALL                                         $44     
         61        MUL                                              ~45     $44, 2
         62        ASSIGN                                                   !8, ~45
   91    63        MUL                                              ~47     !4, !8
         64        ASSIGN                                                   !9, ~47
   93    65      > RETURN                                                   !9
   94    66*     > RETURN                                                   null

End of function getdistance3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
276.95 ms | 1039 KiB | 24 Q