3v4l.org

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

End of function arraytoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.89 ms | 1411 KiB | 20 Q