3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToXml($array, \SimpleXMLElement $xml) { foreach ($array as $key => $value) { if (is_array($value)) { if (!is_numeric($key)) { $subNode = $xml->addChild($key); } else { $subNode = $xml->addChild('item' . $key); } arrayToXml($value, $subNode); } else { $xml->addChild($key, htmlspecialchars($value)); } } } $array = [ 'key' => 'value', 'arrKey' => [ 'subkey1' => 1, 'subkey2' => 2, ], 0 => 'numeric zero', 1 => 'another', 2 => [ 'adin', 'two', 'three' ], ]; $xml = new \SimpleXMLElement('<response/>'); arrayToXml($array, $xml); echo $xml->asXML(); echo PHP_EOL; $xml = new SimpleXMLElement('<response/>'); array_walk_recursive(array_flip($array), array ($xml, 'addChild')); print $xml->asXML();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KZ0JI
function name:  (null)
number of ops:  30
compiled vars:  !0 = $array, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   32     1        NEW                                              $3      'SimpleXMLElement'
          2        SEND_VAL_EX                                              '%3Cresponse%2F%3E'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   34     5        INIT_FCALL                                               'arraytoxml'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0          
   36     9        INIT_METHOD_CALL                                         !1, 'asXML'
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
   38    12        ECHO                                                     '%0A'
   40    13        NEW                                              $8      'SimpleXMLElement'
         14        SEND_VAL_EX                                              '%3Cresponse%2F%3E'
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !1, $8
   41    17        INIT_FCALL                                               'array_walk_recursive'
         18        INIT_FCALL                                               'array_flip'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $11     
         21        SEND_VAR_NO_REF                               0          $11
         22        INIT_ARRAY                                       ~12     !1
         23        ADD_ARRAY_ELEMENT                                ~12     'addChild'
         24        SEND_VAL                                                 ~12
         25        DO_ICALL                                                 
   42    26        INIT_METHOD_CALL                                         !1, 'asXML'
         27        DO_FCALL                                      0  $14     
         28        ECHO                                                     $14
         29      > RETURN                                                   1

Function arraytoxml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/KZ0JI
function name:  arrayToXml
number of ops:  37
compiled vars:  !0 = $array, !1 = $xml, !2 = $value, !3 = $key, !4 = $subNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2      > FE_RESET_R                                       $5      !0, ->35
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->35
          4    >   ASSIGN                                                   !3, ~6
    6     5        TYPE_CHECK                                  128          !2
          6      > JMPZ                                                     ~8, ->27
    7     7    >   INIT_FCALL                                               'is_numeric'
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $9      
         10        BOOL_NOT                                         ~10     $9
         11      > JMPZ                                                     ~10, ->17
    8    12    >   INIT_METHOD_CALL                                         !1, 'addChild'
         13        SEND_VAR_EX                                              !3
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !4, $11
         16      > JMP                                                      ->22
   10    17    >   INIT_METHOD_CALL                                         !1, 'addChild'
         18        CONCAT                                           ~13     'item', !3
         19        SEND_VAL_EX                                              ~13
         20        DO_FCALL                                      0  $14     
         21        ASSIGN                                                   !4, $14
   12    22    >   INIT_FCALL_BY_NAME                                       'arrayToXml'
         23        SEND_VAR_EX                                              !2
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0          
         26      > JMP                                                      ->34
   14    27    >   INIT_METHOD_CALL                                         !1, 'addChild'
         28        SEND_VAR_EX                                              !3
         29        INIT_FCALL                                               'htmlspecialchars'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                         $17     
         32        SEND_VAR_NO_REF_EX                                       $17
         33        DO_FCALL                                      0          
    5    34    > > JMP                                                      ->3
         35    >   FE_FREE                                                  $5
   17    36      > RETURN                                                   null

End of function arraytoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.69 ms | 1407 KiB | 22 Q