3v4l.org

run code in 500+ 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 = 32
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 32
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 31
Branch analysis from position: 27
Branch analysis from position: 22
Branch analysis from position: 18
Branch analysis from position: 13
Branch analysis from position: 9
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/WCTQi
function name:  getAddress
number of ops:  35
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, ->32
          3    > > FE_FETCH_R                                                   $4, !2, ->32
   82     4    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~5      !2, 'types'
          5      > JMPZ_EX                                              ~5      ~5, ->9
          6    >   FETCH_DIM_R                                          ~6      !2, 'types'
          7        FRAMELESS_ICALL_2                in_array            ~7      'street_number', ~6
          8        BOOL                                                 ~5      ~7
          9    > > JMPZ                                                         ~5, ->13
         10    >   FETCH_DIM_R                                          ~9      !2, 'long_name'
         11        ASSIGN_DIM                                                   !1, 'street_number'
         12        OP_DATA                                                      ~9
   83    13    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~10     !2, 'types'
         14      > JMPZ_EX                                              ~10     ~10, ->18
         15    >   FETCH_DIM_R                                          ~11     !2, 'types'
         16        FRAMELESS_ICALL_2                in_array            ~12     'street_number', ~11
         17        BOOL                                                 ~10     ~12
         18    > > JMPZ                                                         ~10, ->22
         19    >   FETCH_DIM_R                                          ~14     !2, 'long_name'
         20        ASSIGN_DIM                                                   !1, 'route'
         21        OP_DATA                                                      ~14
   84    22    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~15     !2, 'types'
         23      > JMPZ_EX                                              ~15     ~15, ->27
         24    >   FETCH_DIM_R                                          ~16     !2, 'types'
         25        FRAMELESS_ICALL_2                in_array            ~17     'administrative_area_level_2', ~16
         26        BOOL                                                 ~15     ~17
         27    > > JMPZ                                                         ~15, ->31
         28    >   FETCH_DIM_R                                          ~19     !2, 'long_name'
         29        ASSIGN_DIM                                                   !1, 'city'
         30        OP_DATA                                                      ~19
   81    31    > > JMP                                                          ->3
         32    >   FE_FREE                                                      $4
   86    33      > RETURN                                                       !1
   87    34*     > RETURN                                                       null

End of function getaddress

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
190.11 ms | 2954 KiB | 16 Q