3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @link http://stackoverflow.com/questions/28965063/php-access-array-within-xml */ $buffer = <<<XML <root> <merchant id="1" name="companyname"> <prod id="690579815" lang="en" pre_order="no" web_offer="yes" in_stock="yes">product #1</prod> <prod id="250544605" lang="en" pre_order="no" web_offer="yes" in_stock="yes">product #2</prod> <prod id="360355798" lang="en" pre_order="no" web_offer="yes" in_stock="yes">product #3</prod> </merchant> </root> XML; $data = simplexml_load_string($buffer); var_dump($data['prod']); var_dump(count($data['prod'])); $merchant = $data->merchant; var_dump(count($merchant->prod)); var_dump($merchant->prod[0]->asXML()); var_dump($merchant->prod[0]['id']->asXML()); var_dump((string)$merchant->prod[0]); var_dump((string)$merchant->prod[0]['id']); echo $merchant->prod[0]; // prints: "product #1" echo "\n"; foreach ($merchant->prod as $prod) { echo $prod->asXML(), "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 61
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 61
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
filename:       /in/HuLc7
function name:  (null)
number of ops:  63
compiled vars:  !0 = $buffer, !1 = $data, !2 = $merchant, !3 = $prod
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, '%3Croot%3E%0A++++%3Cmerchant+id%3D%221%22+name%3D%22companyname%22%3E%0A++++++++%3Cprod+id%3D%22690579815%22+lang%3D%22en%22+pre_order%3D%22no%22+web_offer%3D%22yes%22+in_stock%3D%22yes%22%3Eproduct+%231%3C%2Fprod%3E%0A++++++++%3Cprod+id%3D%22250544605%22+lang%3D%22en%22+pre_order%3D%22no%22+web_offer%3D%22yes%22+in_stock%3D%22yes%22%3Eproduct+%232%3C%2Fprod%3E%0A++++++++%3Cprod+id%3D%22360355798%22+lang%3D%22en%22+pre_order%3D%22no%22+web_offer%3D%22yes%22+in_stock%3D%22yes%22%3Eproduct+%233%3C%2Fprod%3E%0A++++%3C%2Fmerchant%3E%0A%3C%2Froot%3E'
   16     1        INIT_FCALL                                               'simplexml_load_string'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
   18     5        INIT_FCALL                                               'var_dump'
          6        FETCH_DIM_R                                      ~7      !1, 'prod'
          7        SEND_VAL                                                 ~7
          8        DO_ICALL                                                 
   19     9        INIT_FCALL                                               'var_dump'
         10        FETCH_DIM_R                                      ~9      !1, 'prod'
         11        COUNT                                            ~10     ~9
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                                 
   21    14        FETCH_OBJ_R                                      ~12     !1, 'merchant'
         15        ASSIGN                                                   !2, ~12
   22    16        INIT_FCALL                                               'var_dump'
         17        FETCH_OBJ_R                                      ~14     !2, 'prod'
         18        COUNT                                            ~15     ~14
         19        SEND_VAL                                                 ~15
         20        DO_ICALL                                                 
   25    21        INIT_FCALL                                               'var_dump'
         22        FETCH_OBJ_R                                      ~17     !2, 'prod'
         23        FETCH_DIM_R                                      ~18     ~17, 0
         24        INIT_METHOD_CALL                                         ~18, 'asXML'
         25        DO_FCALL                                      0  $19     
         26        SEND_VAR                                                 $19
         27        DO_ICALL                                                 
   26    28        INIT_FCALL                                               'var_dump'
         29        FETCH_OBJ_R                                      ~21     !2, 'prod'
         30        FETCH_DIM_R                                      ~22     ~21, 0
         31        FETCH_DIM_R                                      ~23     ~22, 'id'
         32        INIT_METHOD_CALL                                         ~23, 'asXML'
         33        DO_FCALL                                      0  $24     
         34        SEND_VAR                                                 $24
         35        DO_ICALL                                                 
   29    36        INIT_FCALL                                               'var_dump'
         37        FETCH_OBJ_R                                      ~26     !2, 'prod'
         38        FETCH_DIM_R                                      ~27     ~26, 0
         39        CAST                                          6  ~28     ~27
         40        SEND_VAL                                                 ~28
         41        DO_ICALL                                                 
   30    42        INIT_FCALL                                               'var_dump'
         43        FETCH_OBJ_R                                      ~30     !2, 'prod'
         44        FETCH_DIM_R                                      ~31     ~30, 0
         45        FETCH_DIM_R                                      ~32     ~31, 'id'
         46        CAST                                          6  ~33     ~32
         47        SEND_VAL                                                 ~33
         48        DO_ICALL                                                 
   32    49        FETCH_OBJ_R                                      ~35     !2, 'prod'
         50        FETCH_DIM_R                                      ~36     ~35, 0
         51        ECHO                                                     ~36
   34    52        ECHO                                                     '%0A'
   36    53        FETCH_OBJ_R                                      ~37     !2, 'prod'
         54      > FE_RESET_R                                       $38     ~37, ->61
         55    > > FE_FETCH_R                                               $38, !3, ->61
   38    56    >   INIT_METHOD_CALL                                         !3, 'asXML'
         57        DO_FCALL                                      0  $39     
         58        ECHO                                                     $39
         59        ECHO                                                     '%0A'
   36    60      > JMP                                                      ->55
         61    >   FE_FREE                                                  $38
   39    62      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.53 ms | 1405 KiB | 17 Q