3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = <<<XML <?xml version="1.0" encoding="utf-8"?> <root> <result> <node> <title> Some Title Name</title> <categories> <category> categor_one </category> <category> categor_two </category> </categories> </node> <node> <title> Some Title Name</title> <categories> <category> categor_one </category> <category> categor_tree </category> </categories> </node> </result> </root> XML; $products = array(); $product_data = array(); $xml = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA); foreach ($xml->result->node as $node) { $product_data['title'] = (string)$node->title; foreach($node->categories as $category) { if (is_array($category)) { $product_data['category'] = implode('///', $category); continue; } $product_data['category'] = (array)$category->category; } $products[(string)$node->title][] = $product_data; } $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $root = $xmlDoc->appendChild($xmlDoc->createElement("root")); foreach ($products as $key => $product) { $productA = $root->appendChild($xmlDoc->createElement('product')); $productA->appendChild($xmlDoc->createElement("title", $key)); for ($i = 0; $i < count($product); $i++) { $productA->appendChild($xmlDoc->createElement("category" . $i, implode("///", $product[$i]["category"]))); } } $xmlDoc->formatOutput = true; echo $xmlDoc->saveXML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 41
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 41
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 34
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 34
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 34
Branch analysis from position: 41
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 92
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 92
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 73
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 73
Branch analysis from position: 91
Branch analysis from position: 73
Branch analysis from position: 92
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 92
Branch analysis from position: 41
filename:       /in/9aJe9
function name:  (null)
number of ops:  99
compiled vars:  !0 = $xml, !1 = $products, !2 = $product_data, !3 = $node, !4 = $category, !5 = $xmlDoc, !6 = $root, !7 = $product, !8 = $key, !9 = $productA, !10 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Croot%3E%0A++++%3Cresult%3E%0A++++++++%3Cnode%3E%0A++++++++++++%3Ctitle%3E+Some+Title+Name%3C%2Ftitle%3E%0A++++++++++++%3Ccategories%3E%0A++++++++++++++++%3Ccategory%3E+categor_one+%3C%2Fcategory%3E%0A++++++++++++++++%3Ccategory%3E+categor_two+%3C%2Fcategory%3E%0A++++++++++++%3C%2Fcategories%3E%0A++++++++%3C%2Fnode%3E%0A%0A++++++++%3Cnode%3E%0A++++++++++++%3Ctitle%3E+Some+Title+Name%3C%2Ftitle%3E%0A++++++++++++%3Ccategories%3E%0A++++++++++++++++%3Ccategory%3E+categor_one+%3C%2Fcategory%3E%0A++++++++++++++++%3Ccategory%3E+categor_tree+%3C%2Fcategory%3E%0A++++++++++++%3C%2Fcategories%3E%0A++++++++%3C%2Fnode%3E%0A++++%3C%2Fresult%3E%0A%3C%2Froot%3E'
   26     1        ASSIGN                                                   !1, <array>
   27     2        ASSIGN                                                   !2, <array>
   28     3        INIT_FCALL                                               'simplexml_load_string'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'SimpleXMLElement'
          6        SEND_VAL                                                 16384
          7        DO_ICALL                                         $14     
          8        ASSIGN                                                   !0, $14
   30     9        FETCH_OBJ_R                                      ~16     !0, 'result'
         10        FETCH_OBJ_R                                      ~17     ~16, 'node'
         11      > FE_RESET_R                                       $18     ~17, ->41
         12    > > FE_FETCH_R                                               $18, !3, ->41
   31    13    >   FETCH_OBJ_R                                      ~20     !3, 'title'
         14        CAST                                          6  ~21     ~20
         15        ASSIGN_DIM                                               !2, 'title'
         16        OP_DATA                                                  ~21
   32    17        FETCH_OBJ_R                                      ~22     !3, 'categories'
         18      > FE_RESET_R                                       $23     ~22, ->34
         19    > > FE_FETCH_R                                               $23, !4, ->34
   33    20    >   TYPE_CHECK                                  128          !4
         21      > JMPZ                                                     ~24, ->29
   34    22    >   INIT_FCALL                                               'implode'
         23        SEND_VAL                                                 '%2F%2F%2F'
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $26     
         26        ASSIGN_DIM                                               !2, 'category'
         27        OP_DATA                                                  $26
   35    28      > JMP                                                      ->19
   37    29    >   FETCH_OBJ_R                                      ~28     !4, 'category'
         30        CAST                                          7  ~29     ~28
         31        ASSIGN_DIM                                               !2, 'category'
         32        OP_DATA                                                  ~29
   32    33      > JMP                                                      ->19
         34    >   FE_FREE                                                  $23
   39    35        FETCH_OBJ_R                                      ~30     !3, 'title'
         36        CAST                                          6  ~31     ~30
         37        FETCH_DIM_W                                      $32     !1, ~31
         38        ASSIGN_DIM                                               $32
         39        OP_DATA                                                  !2
   30    40      > JMP                                                      ->12
         41    >   FE_FREE                                                  $18
   42    42        NEW                                              $34     'DOMDocument'
         43        SEND_VAL_EX                                              '1.0'
         44        SEND_VAL_EX                                              'UTF-8'
         45        DO_FCALL                                      0          
         46        ASSIGN                                                   !5, $34
   43    47        INIT_METHOD_CALL                                         !5, 'appendChild'
         48        INIT_METHOD_CALL                                         !5, 'createElement'
         49        SEND_VAL_EX                                              'root'
         50        DO_FCALL                                      0  $37     
         51        SEND_VAR_NO_REF_EX                                       $37
         52        DO_FCALL                                      0  $38     
         53        ASSIGN                                                   !6, $38
   44    54      > FE_RESET_R                                       $40     !1, ->92
         55    > > FE_FETCH_R                                       ~41     $40, !7, ->92
         56    >   ASSIGN                                                   !8, ~41
   45    57        INIT_METHOD_CALL                                         !6, 'appendChild'
         58        INIT_METHOD_CALL                                         !5, 'createElement'
         59        SEND_VAL_EX                                              'product'
         60        DO_FCALL                                      0  $43     
         61        SEND_VAR_NO_REF_EX                                       $43
         62        DO_FCALL                                      0  $44     
         63        ASSIGN                                                   !9, $44
   46    64        INIT_METHOD_CALL                                         !9, 'appendChild'
         65        INIT_METHOD_CALL                                         !5, 'createElement'
         66        SEND_VAL_EX                                              'title'
         67        SEND_VAR_EX                                              !8
         68        DO_FCALL                                      0  $46     
         69        SEND_VAR_NO_REF_EX                                       $46
         70        DO_FCALL                                      0          
   47    71        ASSIGN                                                   !10, 0
         72      > JMP                                                      ->88
   48    73    >   INIT_METHOD_CALL                                         !9, 'appendChild'
         74        INIT_METHOD_CALL                                         !5, 'createElement'
         75        CONCAT                                           ~49     'category', !10
         76        SEND_VAL_EX                                              ~49
         77        INIT_FCALL                                               'implode'
         78        SEND_VAL                                                 '%2F%2F%2F'
         79        FETCH_DIM_R                                      ~50     !7, !10
         80        FETCH_DIM_R                                      ~51     ~50, 'category'
         81        SEND_VAL                                                 ~51
         82        DO_ICALL                                         $52     
         83        SEND_VAR_NO_REF_EX                                       $52
         84        DO_FCALL                                      0  $53     
         85        SEND_VAR_NO_REF_EX                                       $53
         86        DO_FCALL                                      0          
   47    87        PRE_INC                                                  !10
         88    >   COUNT                                            ~56     !7
         89        IS_SMALLER                                               !10, ~56
         90      > JMPNZ                                                    ~57, ->73
   44    91    > > JMP                                                      ->55
         92    >   FE_FREE                                                  $40
   51    93        ASSIGN_OBJ                                               !5, 'formatOutput'
         94        OP_DATA                                                  <true>
   52    95        INIT_METHOD_CALL                                         !5, 'saveXML'
         96        DO_FCALL                                      0  $59     
         97        ECHO                                                     $59
         98      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
224.25 ms | 1020 KiB | 15 Q