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

End of function arraytoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.88 ms | 1411 KiB | 20 Q