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 ); 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 = 42
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 42
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/78Pjl
function name:  array_to_xml_aux
number of ops:  44
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, ->42
          4    > > FE_FETCH_R                                           ~8      $7, !3, ->42
          5    >   ASSIGN                                                       !4, ~8
   13     6        FETCH_DIM_R                                          ~10     !4, 0
          7        IS_EQUAL                                                     ~10, '%40'
          8      > JMPZ                                                         ~11, ->16
   14     9    >   INIT_METHOD_CALL                                             !1, 'setAttribute'
   15    10        FRAMELESS_ICALL_2                substr              ~12     !4, 1
         11        SEND_VAL_EX                                                  ~12
         12        SEND_VAR_EX                                                  !3
   14    13        DO_FCALL                                          0          
   18    14        FE_FREE                                                      $7
         15      > RETURN                                                       null
   21    16    >   FRAMELESS_ICALL_1                is_numeric          ~14     !4
         17      > JMPZ                                                         ~14, ->19
   22    18    >   ASSIGN                                                       !4, !2
   25    19    >   TYPE_CHECK                                      128          !3
         20      > JMPZ                                                         ~16, ->34
   26    21    >   NEW                                                  $17     'DOMElement'
         22        SEND_VAR_EX                                                  !4
         23        DO_FCALL                                          0          
         24        ASSIGN                                                       !5, $17
   27    25        INIT_METHOD_CALL                                             !1, 'appendChild'
         26        SEND_VAR_EX                                                  !5
         27        DO_FCALL                                          0          
   28    28        INIT_FCALL_BY_NAME                                           'array_to_xml_aux'
         29        SEND_VAR_EX                                                  !3
         30        SEND_VAR_EX                                                  !5
         31        SEND_VAR_EX                                                  !4
         32        DO_FCALL                                          0          
   25    33      > JMP                                                          ->41
   30    34    >   INIT_METHOD_CALL                                             !6, 'appendChild'
         35        NEW                                                  $22     'DOMElement'
         36        SEND_VAR_EX                                                  !4
         37        SEND_VAR_EX                                                  !3
         38        DO_FCALL                                          0          
         39        SEND_VAR_NO_REF_EX                                           $22
         40        DO_FCALL                                          0          
   12    41    > > JMP                                                          ->4
         42    >   FE_FREE                                                      $7
   33    43      > RETURN                                                       null

End of function array_to_xml_aux

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.53 ms | 2703 KiB | 14 Q