3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_to_xml($data, &$xml_data) { foreach ($data as $key => $value) { if (is_array($value)) { if (is_numeric($key)){ $key = 'item'.$key; //dealing with <0/>..<n/> issues } $subnode = $xml_data->addChild($key); array_to_xml($value, $subnode); } else { $xml_data->addChild("$key",htmlspecialchars("$value")); } } } $requestResult = <<<EOT { "name": "Benjamin Clementine", "mbid_id": "578e5d1c-be21-4158-b147-30aad67f207d", "albums": { "68e65535-f133-408d-93dd-205e9555eaa5": { "albumcover": [ { "id": "172070", "url": "http://assets.fanart.tv/fanart/music/578e5d1c-be21-4158-b147-30aad67f207d/albumcover/at-least-for-now-55b74dfa59411.jpg", "likes": "0" } ] } } } EOT; $decodedResult = json_decode($requestResult, true); $xmlELement = new SimpleXMLElement('<root/>'); array_to_xml($decodedResult, $xmlElement); print_r($xmlElement->xpath('//albumcover/url'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/44k13
function name:  (null)
number of ops:  21
compiled vars:  !0 = $requestResult, !1 = $decodedResult, !2 = $xmlELement, !3 = $xmlElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, '%7B%0A++++%22name%22%3A+%22Benjamin+Clementine%22%2C%0A++++%22mbid_id%22%3A+%22578e5d1c-be21-4158-b147-30aad67f207d%22%2C%0A++++%22albums%22%3A+%7B%0A++++++++%2268e65535-f133-408d-93dd-205e9555eaa5%22%3A+%7B%0A++++++++++++%22albumcover%22%3A+%5B%0A++++++++++++++++%7B%0A++++++++++++++++++++%22id%22%3A+%22172070%22%2C%0A++++++++++++++++++++%22url%22%3A+%22http%3A%2F%2Fassets.fanart.tv%2Ffanart%2Fmusic%2F578e5d1c-be21-4158-b147-30aad67f207d%2Falbumcover%2Fat-least-for-now-55b74dfa59411.jpg%22%2C%0A++++++++++++++++++++%22likes%22%3A+%220%22%0A++++++++++++++++%7D%0A++++++++++++%5D%0A++++++++%7D%0A++++%7D%0A%7D'
   35     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   37     6        NEW                                              $7      'SimpleXMLElement'
          7        SEND_VAL_EX                                              '%3Croot%2F%3E'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $7
   38    10        INIT_FCALL                                               'array_to_xml'
         11        SEND_VAR                                                 !1
         12        SEND_REF                                                 !3
         13        DO_FCALL                                      0          
   40    14        INIT_FCALL                                               'print_r'
         15        INIT_METHOD_CALL                                         !3, 'xpath'
         16        SEND_VAL_EX                                              '%2F%2Falbumcover%2Furl'
         17        DO_FCALL                                      0  $11     
         18        SEND_VAR                                                 $11
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function array_to_xml:
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 = 43) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/44k13
function name:  array_to_xml
number of ops:  34
compiled vars:  !0 = $data, !1 = $xml_data, !2 = $value, !3 = $key, !4 = $subnode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2      > FE_RESET_R                                       $5      !0, ->32
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->32
          4    >   ASSIGN                                                   !3, ~6
    5     5        TYPE_CHECK                                  128          !2
          6      > JMPZ                                                     ~8, ->22
    6     7    >   INIT_FCALL                                               'is_numeric'
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $9      
         10      > JMPZ                                                     $9, ->13
    7    11    >   CONCAT                                           ~10     'item', !3
         12        ASSIGN                                                   !3, ~10
    9    13    >   INIT_METHOD_CALL                                         !1, 'addChild'
         14        SEND_VAR_EX                                              !3
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !4, $12
   10    17        INIT_FCALL_BY_NAME                                       'array_to_xml'
         18        SEND_VAR_EX                                              !2
         19        SEND_VAR_EX                                              !4
         20        DO_FCALL                                      0          
         21      > JMP                                                      ->31
   12    22    >   INIT_METHOD_CALL                                         !1, 'addChild'
         23        CAST                                          6  ~15     !3
         24        SEND_VAL_EX                                              ~15
         25        INIT_FCALL                                               'htmlspecialchars'
         26        CAST                                          6  ~16     !2
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                         $17     
         29        SEND_VAR_NO_REF_EX                                       $17
         30        DO_FCALL                                      0          
    4    31    > > JMP                                                      ->3
         32    >   FE_FREE                                                  $5
   15    33      > RETURN                                                   null

End of function array_to_xml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.8 ms | 1403 KiB | 22 Q