3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToXml($data, \SimpleXmlElement $element, $parent = null) { echo 'data: '; var_dump($data) ; echo $element->asXml(); echo 'parent: '.$parent; foreach ($data as $key => $value) { if (is_array($value) || $value instanceof \Traversable) { if (!is_numeric($key)) { if (count($value) > 0 && isset($value[0])) { arrayToXml($value, $element, $key); } else { $subnode = $element->addChild($key); arrayToXml($value, $subnode, $key); } } else { $subnode = $element->addChild($parent); arrayToXml($value, $subnode, $parent); } } else { if (!is_numeric($key)) { if (substr($key, 0, 1) === '@') { $element->addAttribute(substr($key, 1), $value); } elseif ($key === 'value' and count($data) === 1) { $element->{0} = $value; } elseif (is_bool($value)) { $element->addChild($key, intval($value)); } else { $element->addChild($key, htmlspecialchars($value, ENT_QUOTES)); } } else { $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES)); } } } } $data = array('x' => array('value' => 'test')); $doc = new \SimpleXMLElement('<resource href="/"></resource>'); arrayToXml($data, $doc); echo $doc->asXml(); //$xml = new \SimpleXMLElement('<resource href="/"><x><0>test</0></x></resource>'); //echo $xml->x;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fnMUr
function name:  (null)
number of ops:  13
compiled vars:  !0 = $data, !1 = $doc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, <array>
   37     1        NEW                                              $3      'SimpleXMLElement'
          2        SEND_VAL_EX                                              '%3Cresource+href%3D%22%2F%22%3E%3C%2Fresource%3E'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   39     5        INIT_FCALL                                               'arraytoxml'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0          
   41     9        INIT_METHOD_CALL                                         !1, 'asXml'
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
   43    12      > RETURN                                                   1

Function arraytoxml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 113
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 113
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 57
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 47
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 30
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 104
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 78
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 78
2 jumps found. (Code = 46) Position 1 = 80, Position 2 = 83
Branch analysis from position: 80
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 87
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 95
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 83
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
Branch analysis from position: 113
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 113
filename:       /in/fnMUr
function name:  arrayToXml
number of ops:  115
compiled vars:  !0 = $data, !1 = $element, !2 = $parent, !3 = $value, !4 = $key, !5 = $subnode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    4     3        ECHO                                                     'data%3A+'
          4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
          7        INIT_METHOD_CALL                                         !1, 'asXml'
          8        DO_FCALL                                      0  $7      
          9        ECHO                                                     $7
         10        CONCAT                                           ~8      'parent%3A+', !2
         11        ECHO                                                     ~8
    5    12      > FE_RESET_R                                       $9      !0, ->113
         13    > > FE_FETCH_R                                       ~10     $9, !3, ->113
         14    >   ASSIGN                                                   !4, ~10
    6    15        TYPE_CHECK                                  128  ~12     !3
         16      > JMPNZ_EX                                         ~12     ~12, ->19
         17    >   INSTANCEOF                                       ~13     !3, 'Traversable'
         18        BOOL                                             ~12     ~13
         19    > > JMPZ                                                     ~12, ->57
    7    20    >   INIT_FCALL                                               'is_numeric'
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                         $14     
         23        BOOL_NOT                                         ~15     $14
         24      > JMPZ                                                     ~15, ->47
    8    25    >   COUNT                                            ~16     !3
         26        IS_SMALLER                                       ~17     0, ~16
         27      > JMPZ_EX                                          ~17     ~17, ->30
         28    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !3, 0
         29        BOOL                                             ~17     ~18
         30    > > JMPZ                                                     ~17, ->37
    9    31    >   INIT_FCALL_BY_NAME                                       'arrayToXml'
         32        SEND_VAR_EX                                              !3
         33        SEND_VAR_EX                                              !1
         34        SEND_VAR_EX                                              !4
         35        DO_FCALL                                      0          
         36      > JMP                                                      ->46
   11    37    >   INIT_METHOD_CALL                                         !1, 'addChild'
         38        SEND_VAR_EX                                              !4
         39        DO_FCALL                                      0  $20     
         40        ASSIGN                                                   !5, $20
   12    41        INIT_FCALL_BY_NAME                                       'arrayToXml'
         42        SEND_VAR_EX                                              !3
         43        SEND_VAR_EX                                              !5
         44        SEND_VAR_EX                                              !4
         45        DO_FCALL                                      0          
         46    > > JMP                                                      ->56
   15    47    >   INIT_METHOD_CALL                                         !1, 'addChild'
         48        SEND_VAR_EX                                              !2
         49        DO_FCALL                                      0  $23     
         50        ASSIGN                                                   !5, $23
   16    51        INIT_FCALL_BY_NAME                                       'arrayToXml'
         52        SEND_VAR_EX                                              !3
         53        SEND_VAR_EX                                              !5
         54        SEND_VAR_EX                                              !2
         55        DO_FCALL                                      0          
         56    > > JMP                                                      ->112
   19    57    >   INIT_FCALL                                               'is_numeric'
         58        SEND_VAR                                                 !4
         59        DO_ICALL                                         $26     
         60        BOOL_NOT                                         ~27     $26
         61      > JMPZ                                                     ~27, ->104
   20    62    >   INIT_FCALL                                               'substr'
         63        SEND_VAR                                                 !4
         64        SEND_VAL                                                 0
         65        SEND_VAL                                                 1
         66        DO_ICALL                                         $28     
         67        IS_IDENTICAL                                             $28, '%40'
         68      > JMPZ                                                     ~29, ->78
   21    69    >   INIT_METHOD_CALL                                         !1, 'addAttribute'
         70        INIT_FCALL                                               'substr'
         71        SEND_VAR                                                 !4
         72        SEND_VAL                                                 1
         73        DO_ICALL                                         $30     
         74        SEND_VAR_NO_REF_EX                                       $30
         75        SEND_VAR_EX                                              !3
         76        DO_FCALL                                      0          
         77      > JMP                                                      ->103
   22    78    >   IS_IDENTICAL                                     ~32     !4, 'value'
         79      > JMPZ_EX                                          ~32     ~32, ->83
         80    >   COUNT                                            ~33     !0
         81        IS_IDENTICAL                                     ~34     ~33, 1
         82        BOOL                                             ~32     ~34
         83    > > JMPZ                                                     ~32, ->87
   23    84    >   ASSIGN_OBJ                                               !1, '0'
         85        OP_DATA                                                  !3
         86      > JMP                                                      ->103
   24    87    >   TYPE_CHECK                                   12          !3
         88      > JMPZ                                                     ~36, ->95
   25    89    >   INIT_METHOD_CALL                                         !1, 'addChild'
         90        SEND_VAR_EX                                              !4
         91        CAST                                          4  ~37     !3
         92        SEND_VAL_EX                                              ~37
         93        DO_FCALL                                      0          
         94      > JMP                                                      ->103
   27    95    >   INIT_METHOD_CALL                                         !1, 'addChild'
         96        SEND_VAR_EX                                              !4
         97        INIT_FCALL                                               'htmlspecialchars'
         98        SEND_VAR                                                 !3
         99        SEND_VAL                                                 3
        100        DO_ICALL                                         $39     
        101        SEND_VAR_NO_REF_EX                                       $39
        102        DO_FCALL                                      0          
        103    > > JMP                                                      ->112
   30   104    >   INIT_METHOD_CALL                                         !1, 'addChild'
        105        SEND_VAR_EX                                              !2
        106        INIT_FCALL                                               'htmlspecialchars'
        107        SEND_VAR                                                 !3
        108        SEND_VAL                                                 3
        109        DO_ICALL                                         $41     
        110        SEND_VAR_NO_REF_EX                                       $41
        111        DO_FCALL                                      0          
    5   112    > > JMP                                                      ->13
        113    >   FE_FREE                                                  $9
   34   114      > RETURN                                                   null

End of function arraytoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.65 ms | 1411 KiB | 22 Q