3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getLatLong($address) { $address = str_replace(' ', '+', $address); $url = 'http://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&sensor=false'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $geoloc = curl_exec($ch); $json = json_decode($geoloc); return array($json->results[0]->geometry->location->lat, $json->results[0]->geometry->location->lng); } $address = getLatLong('Guildford'); $address = getLatLong('BH15 2BT'); $address = getLatLong('10 Downing Street, London'); function Haversine($start, $finish) { $theta = $start[1] - $finish[1]; $distance = (sin(deg2rad($start[0])) * sin(deg2rad($finish[0]))) + (cos(deg2rad($start[0])) * cos(deg2rad($finish[0])) * cos(deg2rad($theta))); $distance = acos($distance); $distance = rad2deg($distance); $distance = $distance * 60 * 1.1515; return round($distance, 2); } $start = getLatLong('Guildford'); $finish = getLatLong('BH15 2BT'); $distance = Haversine($start, $finish); print('<p>The distance between ['.$start[0].', '.$start[1].'] and ['.$finish[0].', '.$finish[1].'] is '.$distance.' miles ('.($distance * 1.609344).' km).</p>'); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uKoWi
function name:  (null)
number of ops:  44
compiled vars:  !0 = $address, !1 = $start, !2 = $finish, !3 = $distance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'getlatlong'
          1        SEND_VAL                                                 'Guildford'
          2        DO_FCALL                                      0  $4      
          3        ASSIGN                                                   !0, $4
   16     4        INIT_FCALL                                               'getlatlong'
          5        SEND_VAL                                                 'BH15+2BT'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !0, $6
   17     8        INIT_FCALL                                               'getlatlong'
          9        SEND_VAL                                                 '10+Downing+Street%2C+London'
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !0, $8
   30    12        INIT_FCALL                                               'getlatlong'
         13        SEND_VAL                                                 'Guildford'
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !1, $10
   31    16        INIT_FCALL                                               'getlatlong'
         17        SEND_VAL                                                 'BH15+2BT'
         18        DO_FCALL                                      0  $12     
         19        ASSIGN                                                   !2, $12
   32    20        INIT_FCALL                                               'haversine'
         21        SEND_VAR                                                 !1
         22        SEND_VAR                                                 !2
         23        DO_FCALL                                      0  $14     
         24        ASSIGN                                                   !3, $14
   34    25        FETCH_DIM_R                                      ~16     !1, 0
         26        CONCAT                                           ~17     '%3Cp%3EThe+distance+between+%5B', ~16
         27        CONCAT                                           ~18     ~17, '%2C+'
         28        FETCH_DIM_R                                      ~19     !1, 1
         29        CONCAT                                           ~20     ~18, ~19
         30        CONCAT                                           ~21     ~20, '%5D+and+%5B'
         31        FETCH_DIM_R                                      ~22     !2, 0
         32        CONCAT                                           ~23     ~21, ~22
         33        CONCAT                                           ~24     ~23, '%2C+'
         34        FETCH_DIM_R                                      ~25     !2, 1
         35        CONCAT                                           ~26     ~24, ~25
         36        CONCAT                                           ~27     ~26, '%5D+is+'
         37        CONCAT                                           ~28     ~27, !3
         38        CONCAT                                           ~29     ~28, '+miles+%28'
         39        MUL                                              ~30     !3, 1.60934
         40        CONCAT                                           ~31     ~29, ~30
         41        CONCAT                                           ~32     ~31, '+km%29.%3C%2Fp%3E'
         42        ECHO                                                     ~32
   35    43      > RETURN                                                   1

Function getlatlong:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uKoWi
function name:  getLatLong
number of ops:  47
compiled vars:  !0 = $address, !1 = $url, !2 = $ch, !3 = $geoloc, !4 = $json
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'str_replace'
          2        SEND_VAL                                                 '+'
          3        SEND_VAL                                                 '%2B'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !0, $5
    5     7        CONCAT                                           ~7      'http%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fgeocode%2Fjson%3Faddress%3D', !0
          8        CONCAT                                           ~8      ~7, '%26sensor%3Dfalse'
          9        ASSIGN                                                   !1, ~8
    6    10        INIT_FCALL_BY_NAME                                       'curl_init'
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !2, $10
    7    13        INIT_FCALL_BY_NAME                                       'curl_setopt'
         14        SEND_VAR_EX                                              !2
         15        FETCH_CONSTANT                                   ~12     'CURLOPT_URL'
         16        SEND_VAL_EX                                              ~12
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
    8    19        INIT_FCALL_BY_NAME                                       'curl_setopt'
         20        SEND_VAR_EX                                              !2
         21        FETCH_CONSTANT                                   ~14     'CURLOPT_RETURNTRANSFER'
         22        SEND_VAL_EX                                              ~14
         23        SEND_VAL_EX                                              1
         24        DO_FCALL                                      0          
    9    25        INIT_FCALL_BY_NAME                                       'curl_exec'
         26        SEND_VAR_EX                                              !2
         27        DO_FCALL                                      0  $16     
         28        ASSIGN                                                   !3, $16
   10    29        INIT_FCALL                                               'json_decode'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $18     
         32        ASSIGN                                                   !4, $18
   12    33        FETCH_OBJ_R                                      ~20     !4, 'results'
         34        FETCH_DIM_R                                      ~21     ~20, 0
         35        FETCH_OBJ_R                                      ~22     ~21, 'geometry'
         36        FETCH_OBJ_R                                      ~23     ~22, 'location'
         37        FETCH_OBJ_R                                      ~24     ~23, 'lat'
         38        INIT_ARRAY                                       ~25     ~24
         39        FETCH_OBJ_R                                      ~26     !4, 'results'
         40        FETCH_DIM_R                                      ~27     ~26, 0
         41        FETCH_OBJ_R                                      ~28     ~27, 'geometry'
         42        FETCH_OBJ_R                                      ~29     ~28, 'location'
         43        FETCH_OBJ_R                                      ~30     ~29, 'lng'
         44        ADD_ARRAY_ELEMENT                                ~25     ~30
         45      > RETURN                                                   ~25
   13    46*     > RETURN                                                   null

End of function getlatlong

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

End of function haversine

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.3 ms | 1411 KiB | 35 Q