3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToXml($data, \SimpleXmlElement $element, $parent = null) { foreach ($data as $key => $value) { echo $key; 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/NsiAl
function name:  (null)
number of ops:  13
compiled vars:  !0 = $data, !1 = $doc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, <array>
   36     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
   38     5        INIT_FCALL                                               'arraytoxml'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0          
   40     9        INIT_METHOD_CALL                                         !1, 'asXml'
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
   42    12      > RETURN                                                   1

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

End of function arraytoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.28 ms | 1411 KiB | 20 Q