3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "results" : [ { "address_components" : [ { "long_name" : "301", "short_name" : "301", "types" : [ "subpremise" ] }, { "long_name" : "880", "short_name" : "880", "types" : [ "street_number" ] }, { "long_name" : "N Street", "short_name" : "N St", "types" : [ "route" ] }, { "long_name" : "South Addition", "short_name" : "South Addition", "types" : [ "neighborhood", "political" ] }, { "long_name" : "Anchorage", "short_name" : "Anchorage", "types" : [ "locality", "political" ] }, { "long_name" : "Anchorage", "short_name" : "Anchorage", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Alaska", "short_name" : "AK", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "99501", "short_name" : "99501", "types" : [ "postal_code" ] } ], "formatted_address" : "880 N Street #301, Anchorage, AK 99501, USA", "geometry" : { "location" : { "lat" : 61.21391800000001, "lng" : -149.908357 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 61.21526698029151, "lng" : -149.9070080197085 }, "southwest" : { "lat" : 61.2125690197085, "lng" : -149.9097059802915 } } }, "partial_match" : true, "types" : [ "subpremise" ] } ], "status" : "OK" }'; function getAddress($elements){ $addr = []; foreach($elements as $e){ if(isset($e['types']) && in_array("street_number",$e['types'])) $addr['street_number'] = $e['long_name']; if(isset($e['types']) && in_array("street_number",$e['types'])) $addr['route'] = $e['long_name']; if(isset($e['types']) && in_array("administrative_area_level_2",$e['types'])) $addr['city'] = $e['long_name']; } return $addr; } $obj = json_decode($json, true); $c = $obj['results'][0]['address_components']; var_dump(getAddress($c));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WCTQi
function name:  (null)
number of ops:  17
compiled vars:  !0 = $json, !1 = $obj, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%0A+++%22results%22+%3A+%5B%0A++++++%7B%0A+++++++++%22address_components%22+%3A+%5B%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22301%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22301%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22subpremise%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22880%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22880%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22street_number%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22N+Street%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22N+St%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22route%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22South+Addition%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22South+Addition%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22neighborhood%22%2C+%22political%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22Anchorage%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22Anchorage%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22locality%22%2C+%22political%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22Anchorage%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22Anchorage%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22administrative_area_level_2%22%2C+%22political%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22Alaska%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22AK%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22administrative_area_level_1%22%2C+%22political%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%22United+States%22%2C%0A+++++++++++++++%22short_name%22+%3A+%22US%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22country%22%2C+%22political%22+%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A+++++++++++++++%22long_name%22+%3A+%2299501%22%2C%0A+++++++++++++++%22short_name%22+%3A+%2299501%22%2C%0A+++++++++++++++%22types%22+%3A+%5B+%22postal_code%22+%5D%0A++++++++++++%7D%0A+++++++++%5D%2C%0A+++++++++%22formatted_address%22+%3A+%22880+N+Street+%23301%2C+Anchorage%2C+AK+99501%2C+USA%22%2C%0A+++++++++%22geometry%22+%3A+%7B%0A++++++++++++%22location%22+%3A+%7B%0A+++++++++++++++%22lat%22+%3A+61.21391800000001%2C%0A+++++++++++++++%22lng%22+%3A+-149.908357%0A++++++++++++%7D%2C%0A++++++++++++%22location_type%22+%3A+%22ROOFTOP%22%2C%0A++++++++++++%22viewport%22+%3A+%7B%0A+++++++++++++++%22northeast%22+%3A+%7B%0A++++++++++++++++++%22lat%22+%3A+61.21526698029151%2C%0A++++++++++++++++++%22lng%22+%3A+-149.9070080197085%0A+++++++++++++++%7D%2C%0A+++++++++++++++%22southwest%22+%3A+%7B%0A++++++++++++++++++%22lat%22+%3A+61.2125690197085%2C%0A++++++++++++++++++%22lng%22+%3A+-149.9097059802915%0A+++++++++++++++%7D%0A++++++++++++%7D%0A+++++++++%7D%2C%0A+++++++++%22partial_match%22+%3A+true%2C%0A+++++++++%22types%22+%3A+%5B+%22subpremise%22+%5D%0A++++++%7D%0A+++%5D%2C%0A+++%22status%22+%3A+%22OK%22%0A%7D'
   90     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   92     6        FETCH_DIM_R                                      ~6      !1, 'results'
          7        FETCH_DIM_R                                      ~7      ~6, 0
          8        FETCH_DIM_R                                      ~8      ~7, 'address_components'
          9        ASSIGN                                                   !2, ~8
   95    10        INIT_FCALL                                               'var_dump'
         11        INIT_FCALL                                               'getaddress'
         12        SEND_VAR                                                 !2
         13        DO_FCALL                                      0  $10     
         14        SEND_VAR                                                 $10
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function getaddress:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 41
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 41
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 40
Branch analysis from position: 36
Branch analysis from position: 28
Branch analysis from position: 24
Branch analysis from position: 16
Branch analysis from position: 12
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/WCTQi
function name:  getAddress
number of ops:  44
compiled vars:  !0 = $elements, !1 = $addr, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   80     1        ASSIGN                                                   !1, <array>
   81     2      > FE_RESET_R                                       $4      !0, ->41
          3    > > FE_FETCH_R                                               $4, !2, ->41
   82     4    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~5      !2, 'types'
          5      > JMPZ_EX                                          ~5      ~5, ->12
          6    >   INIT_FCALL                                               'in_array'
          7        SEND_VAL                                                 'street_number'
          8        FETCH_DIM_R                                      ~6      !2, 'types'
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                         $7      
         11        BOOL                                             ~5      $7
         12    > > JMPZ                                                     ~5, ->16
         13    >   FETCH_DIM_R                                      ~9      !2, 'long_name'
         14        ASSIGN_DIM                                               !1, 'street_number'
         15        OP_DATA                                                  ~9
   83    16    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !2, 'types'
         17      > JMPZ_EX                                          ~10     ~10, ->24
         18    >   INIT_FCALL                                               'in_array'
         19        SEND_VAL                                                 'street_number'
         20        FETCH_DIM_R                                      ~11     !2, 'types'
         21        SEND_VAL                                                 ~11
         22        DO_ICALL                                         $12     
         23        BOOL                                             ~10     $12
         24    > > JMPZ                                                     ~10, ->28
         25    >   FETCH_DIM_R                                      ~14     !2, 'long_name'
         26        ASSIGN_DIM                                               !1, 'route'
         27        OP_DATA                                                  ~14
   84    28    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !2, 'types'
         29      > JMPZ_EX                                          ~15     ~15, ->36
         30    >   INIT_FCALL                                               'in_array'
         31        SEND_VAL                                                 'administrative_area_level_2'
         32        FETCH_DIM_R                                      ~16     !2, 'types'
         33        SEND_VAL                                                 ~16
         34        DO_ICALL                                         $17     
         35        BOOL                                             ~15     $17
         36    > > JMPZ                                                     ~15, ->40
         37    >   FETCH_DIM_R                                      ~19     !2, 'long_name'
         38        ASSIGN_DIM                                               !1, 'city'
         39        OP_DATA                                                  ~19
   81    40    > > JMP                                                      ->3
         41    >   FE_FREE                                                  $4
   86    42      > RETURN                                                   !1
   87    43*     > RETURN                                                   null

End of function getaddress

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.14 ms | 1407 KiB | 20 Q