3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_to_xml(array $data) { $document = new DOMDocument(); array_to_xml_aux($data, $document); $document->formatOutput = true; return $document; } function array_to_xml_aux(array $data, DOMNode $parent, $name = null) { foreach ($data as $key => $value) { if ($key[0] == '@') { $parent->setAttribute( substr($key, 1), $value ); continue; } if (is_numeric($key)) { $key = $name; } if (is_array($value)) { $areAllInt = true; foreach(array_keys($value) as $k) { if (!is_int($k)) { $areAllInt = false; break; } } if ($areAllInt) { array_to_xml_aux($value, $parent, $key); } else { $subnode = new DOMElement($key); $parent->appendChild($subnode); array_to_xml_aux($value, $subnode, $key); } } else { $xml_data->appendChild(new DOMElement($key, $value)); } } } $document = array_to_xml( array( 'Products' => array( 'Product' => array('@name' => 'TR-501'), 'Descricao' => array('@text' => '55.180.198 / 46789771'), 'Detalhes' => array( 'Variacao' => array( array( '@modelo' => 'Palio', '@ano' => '2006', '@motor' => '1.0 FIRE 8V (FLEX)', ), array( '@modelo' => 'Palio2', '@ano' => '2007', '@motor' => '1.0 FIRE 9V (FLEX)', ), ) ), ) ) ); echo $document->saveXML();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BquYA
function name:  (null)
number of ops:  8
compiled vars:  !0 = $document
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                                   'array_to_xml'
   50     1        SEND_VAL                                                     <array>
   47     2        DO_FCALL                                          0  $1      
          3        ASSIGN                                                       !0, $1
   69     4        INIT_METHOD_CALL                                             !0, 'saveXML'
          5        DO_FCALL                                          0  $3      
          6        ECHO                                                         $3
          7      > RETURN                                                       1

Function array_to_xml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BquYA
function name:  array_to_xml
number of ops:  12
compiled vars:  !0 = $data, !1 = $document
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        NEW                                                  $2      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $2
    5     4        INIT_FCALL_BY_NAME                                           'array_to_xml_aux'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAR_EX                                                  !1
          7        DO_FCALL                                          0          
    6     8        ASSIGN_OBJ                                                   !1, 'formatOutput'
          9        OP_DATA                                                      <true>
    7    10      > RETURN                                                       !1
    8    11*     > RETURN                                                       null

End of function array_to_xml

Function array_to_xml_aux:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 61
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 61
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 53
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 40
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 32
Branch analysis from position: 32
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
filename:       /in/BquYA
function name:  array_to_xml_aux
number of ops:  63
compiled vars:  !0 = $data, !1 = $parent, !2 = $name, !3 = $value, !4 = $key, !5 = $areAllInt, !6 = $k, !7 = $subnode, !8 = $xml_data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      null
   12     3      > FE_RESET_R                                           $9      !0, ->61
          4    > > FE_FETCH_R                                           ~10     $9, !3, ->61
          5    >   ASSIGN                                                       !4, ~10
   13     6        FETCH_DIM_R                                          ~12     !4, 0
          7        IS_EQUAL                                                     ~12, '%40'
          8      > JMPZ                                                         ~13, ->15
   14     9    >   INIT_METHOD_CALL                                             !1, 'setAttribute'
   15    10        FRAMELESS_ICALL_2                substr              ~14     !4, 1
         11        SEND_VAL_EX                                                  ~14
         12        SEND_VAR_EX                                                  !3
   14    13        DO_FCALL                                          0          
   18    14      > JMP                                                          ->4
   21    15    >   FRAMELESS_ICALL_1                is_numeric          ~16     !4
         16      > JMPZ                                                         ~16, ->18
   22    17    >   ASSIGN                                                       !4, !2
   25    18    >   TYPE_CHECK                                      128          !3
         19      > JMPZ                                                         ~18, ->53
   26    20    >   ASSIGN                                                       !5, <true>
   27    21        INIT_FCALL                                                   'array_keys'
         22        SEND_VAR                                                     !3
         23        DO_ICALL                                             $20     
         24      > FE_RESET_R                                           $21     $20, ->32
         25    > > FE_FETCH_R                                                   $21, !6, ->32
   28    26    >   TYPE_CHECK                                       16  ~22     !6
         27        BOOL_NOT                                             ~23     ~22
         28      > JMPZ                                                         ~23, ->31
   29    29    >   ASSIGN                                                       !5, <false>
   30    30      > JMP                                                          ->32
   27    31    > > JMP                                                          ->25
         32    >   FE_FREE                                                      $21
   33    33      > JMPZ                                                         !5, ->40
   34    34    >   INIT_FCALL_BY_NAME                                           'array_to_xml_aux'
         35        SEND_VAR_EX                                                  !3
         36        SEND_VAR_EX                                                  !1
         37        SEND_VAR_EX                                                  !4
         38        DO_FCALL                                          0          
   33    39      > JMP                                                          ->52
   36    40    >   NEW                                                  $26     'DOMElement'
         41        SEND_VAR_EX                                                  !4
         42        DO_FCALL                                          0          
         43        ASSIGN                                                       !7, $26
   37    44        INIT_METHOD_CALL                                             !1, 'appendChild'
         45        SEND_VAR_EX                                                  !7
         46        DO_FCALL                                          0          
   38    47        INIT_FCALL_BY_NAME                                           'array_to_xml_aux'
         48        SEND_VAR_EX                                                  !3
         49        SEND_VAR_EX                                                  !7
         50        SEND_VAR_EX                                                  !4
         51        DO_FCALL                                          0          
   25    52    > > JMP                                                          ->60
   42    53    >   INIT_METHOD_CALL                                             !8, 'appendChild'
         54        NEW                                                  $31     'DOMElement'
         55        SEND_VAR_EX                                                  !4
         56        SEND_VAR_EX                                                  !3
         57        DO_FCALL                                          0          
         58        SEND_VAR_NO_REF_EX                                           $31
         59        DO_FCALL                                          0          
   12    60    > > JMP                                                          ->4
         61    >   FE_FREE                                                      $9
   45    62      > RETURN                                                       null

End of function array_to_xml_aux

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
263.03 ms | 2699 KiB | 16 Q