3v4l.org

run code in 300+ 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 ); return; } if (is_numeric($key)) { $key = $name; } if (is_array($value)) { $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/78Pjl
function name:  (null)
number of ops:  8
compiled vars:  !0 = $document
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'array_to_xml'
   38     1        SEND_VAL                                                 <array>
   35     2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   57     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/78Pjl
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 = 47
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 47
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 39
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/78Pjl
function name:  array_to_xml_aux
number of ops:  49
compiled vars:  !0 = $data, !1 = $parent, !2 = $name, !3 = $value, !4 = $key, !5 = $subnode, !6 = $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                                       $7      !0, ->47
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->47
          5    >   ASSIGN                                                   !4, ~8
   13     6        FETCH_DIM_R                                      ~10     !4, 0
          7        IS_EQUAL                                                 ~10, '%40'
          8      > JMPZ                                                     ~11, ->19
   14     9    >   INIT_METHOD_CALL                                         !1, 'setAttribute'
   15    10        INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !4
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $12     
         14        SEND_VAR_NO_REF_EX                                       $12
         15        SEND_VAR_EX                                              !3
   14    16        DO_FCALL                                      0          
   18    17        FE_FREE                                                  $7
         18      > RETURN                                                   null
   21    19    >   INIT_FCALL                                               'is_numeric'
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                         $14     
         22      > JMPZ                                                     $14, ->24
   22    23    >   ASSIGN                                                   !4, !2
   25    24    >   TYPE_CHECK                                  128          !3
         25      > JMPZ                                                     ~16, ->39
   26    26    >   NEW                                              $17     'DOMElement'
         27        SEND_VAR_EX                                              !4
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !5, $17
   27    30        INIT_METHOD_CALL                                         !1, 'appendChild'
         31        SEND_VAR_EX                                              !5
         32        DO_FCALL                                      0          
   28    33        INIT_FCALL_BY_NAME                                       'array_to_xml_aux'
         34        SEND_VAR_EX                                              !3
         35        SEND_VAR_EX                                              !5
         36        SEND_VAR_EX                                              !4
         37        DO_FCALL                                      0          
   25    38      > JMP                                                      ->46
   30    39    >   INIT_METHOD_CALL                                         !6, 'appendChild'
         40        NEW                                              $22     'DOMElement'
         41        SEND_VAR_EX                                              !4
         42        SEND_VAR_EX                                              !3
         43        DO_FCALL                                      0          
         44        SEND_VAR_NO_REF_EX                                       $22
         45        DO_FCALL                                      0          
   12    46    > > JMP                                                      ->4
         47    >   FE_FREE                                                  $7
   33    48      > RETURN                                                   null

End of function array_to_xml_aux

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
187.92 ms | 1468 KiB | 16 Q