3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<person> <child role="son1"> <child role="daughter1"/> </child> <child role="daughter2"> <child role="son2"> <child role="son3"/> </child> </child> </person>'; function xml2assoc($obj, &$arr) { $children = $obj->children(); foreach ( $children as $elementName => $node ) { if (!isset($arr[$elementName])) { $arr[$elementName] = array(); } $temp = array(); $attributes = $node->attributes(); foreach ( $attributes as $attributeName => $attributeValue ) { $attribName = strtolower(trim((string) $attributeName)); $attribVal = trim((string) $attributeValue); $temp[$attribName] = $attribVal; } $text = (string) $node; $text = trim($text); if (strlen($text) > 0) { $temp ['text='] = $text; } $arr[$elementName][] = $temp; $nextIdx = count($arr[$elementName]); xml2assoc($node, $arr[$elementName][$nextIdx - 1]); } return; } $dom = new SimpleXMLElement($xml); $arr = array(); xml2assoc($dom, $arr); print_r($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9S9J9
function name:  (null)
number of ops:  14
compiled vars:  !0 = $xml, !1 = $dom, !2 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Cperson%3E%0A%3Cchild+role%3D%22son1%22%3E%0A%3Cchild+role%3D%22daughter1%22%2F%3E%0A%3C%2Fchild%3E%0A%3Cchild+role%3D%22daughter2%22%3E%0A%3Cchild+role%3D%22son2%22%3E%0A%3Cchild+role%3D%22son3%22%2F%3E%0A%3C%2Fchild%3E%0A%3C%2Fchild%3E%0A%3C%2Fperson%3E'
   39     1        NEW                                              $4      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   40     5        ASSIGN                                                   !2, <array>
   41     6        INIT_FCALL                                               'xml2assoc'
          7        SEND_VAR                                                 !1
          8        SEND_REF                                                 !2
          9        DO_FCALL                                      0          
   42    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function xml2assoc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 63
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 63
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 36
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 36
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 48
Branch analysis from position: 36
Branch analysis from position: 13
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
filename:       /in/9S9J9
function name:  xml2assoc
number of ops:  66
compiled vars:  !0 = $obj, !1 = $arr, !2 = $children, !3 = $node, !4 = $elementName, !5 = $temp, !6 = $attributes, !7 = $attributeValue, !8 = $attributeName, !9 = $attribName, !10 = $attribVal, !11 = $text, !12 = $nextIdx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_METHOD_CALL                                         !0, 'children'
          3        DO_FCALL                                      0  $13     
          4        ASSIGN                                                   !2, $13
   15     5      > FE_RESET_R                                       $15     !2, ->63
          6    > > FE_FETCH_R                                       ~16     $15, !3, ->63
          7    >   ASSIGN                                                   !4, ~16
   17     8        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !1, !4
          9        BOOL_NOT                                         ~19     ~18
         10      > JMPZ                                                     ~19, ->13
   18    11    >   ASSIGN_DIM                                               !1, !4
         12        OP_DATA                                                  <array>
   20    13    >   ASSIGN                                                   !5, <array>
   21    14        INIT_METHOD_CALL                                         !3, 'attributes'
         15        DO_FCALL                                      0  $22     
         16        ASSIGN                                                   !6, $22
   22    17      > FE_RESET_R                                       $24     !6, ->36
         18    > > FE_FETCH_R                                       ~25     $24, !7, ->36
         19    >   ASSIGN                                                   !8, ~25
   23    20        INIT_FCALL                                               'strtolower'
         21        INIT_FCALL                                               'trim'
         22        CAST                                          6  ~27     !8
         23        SEND_VAL                                                 ~27
         24        DO_ICALL                                         $28     
         25        SEND_VAR                                                 $28
         26        DO_ICALL                                         $29     
         27        ASSIGN                                                   !9, $29
   24    28        INIT_FCALL                                               'trim'
         29        CAST                                          6  ~31     !7
         30        SEND_VAL                                                 ~31
         31        DO_ICALL                                         $32     
         32        ASSIGN                                                   !10, $32
   25    33        ASSIGN_DIM                                               !5, !9
         34        OP_DATA                                                  !10
   22    35      > JMP                                                      ->18
         36    >   FE_FREE                                                  $24
   27    37        CAST                                          6  ~35     !3
         38        ASSIGN                                                   !11, ~35
   28    39        INIT_FCALL                                               'trim'
         40        SEND_VAR                                                 !11
         41        DO_ICALL                                         $37     
         42        ASSIGN                                                   !11, $37
   29    43        STRLEN                                           ~39     !11
         44        IS_SMALLER                                               0, ~39
         45      > JMPZ                                                     ~40, ->48
   30    46    >   ASSIGN_DIM                                               !5, 'text%3D'
         47        OP_DATA                                                  !11
   32    48    >   FETCH_DIM_W                                      $42     !1, !4
         49        ASSIGN_DIM                                               $42
         50        OP_DATA                                                  !5
   33    51        FETCH_DIM_R                                      ~44     !1, !4
         52        COUNT                                            ~45     ~44
         53        ASSIGN                                                   !12, ~45
   34    54        INIT_FCALL_BY_NAME                                       'xml2assoc'
         55        SEND_VAR_EX                                              !3
         56        CHECK_FUNC_ARG                                           
         57        SUB                                              ~48     !12, 1
         58        FETCH_DIM_FUNC_ARG                               $47     !1, !4
         59        FETCH_DIM_FUNC_ARG                               $49     $47, ~48
         60        SEND_FUNC_ARG                                            $49
         61        DO_FCALL                                      0          
   15    62      > JMP                                                      ->6
         63    >   FE_FREE                                                  $15
   36    64      > RETURN                                                   null
   37    65*     > RETURN                                                   null

End of function xml2assoc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.44 ms | 1024 KiB | 17 Q