3v4l.org

run code in 500+ 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 = 38
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 38
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 31
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 31
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 52, Position 2 = 86
Branch analysis from position: 52
2 jumps found. (Code = 78) Position 1 = 53, Position 2 = 86
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 70
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 70
Branch analysis from position: 85
Branch analysis from position: 70
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 86
Branch analysis from position: 38
filename:       /in/9aJe9
function name:  (null)
number of ops:  93
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, ->38
         12    > > FE_FETCH_R                                                   $18, !3, ->38
   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, ->31
         19    > > FE_FETCH_R                                                   $23, !4, ->31
   33    20    >   TYPE_CHECK                                      128          !4
         21      > JMPZ                                                         ~24, ->26
   34    22    >   FRAMELESS_ICALL_2                implode             ~26     '%2F%2F%2F', !4
         23        ASSIGN_DIM                                                   !2, 'category'
         24        OP_DATA                                                      ~26
   35    25      > JMP                                                          ->19
   37    26    >   FETCH_OBJ_R                                          ~28     !4, 'category'
         27        CAST                                              7  ~29     ~28
         28        ASSIGN_DIM                                                   !2, 'category'
         29        OP_DATA                                                      ~29
   32    30      > JMP                                                          ->19
         31    >   FE_FREE                                                      $23
   39    32        FETCH_OBJ_R                                          ~30     !3, 'title'
         33        CAST                                              6  ~31     ~30
         34        FETCH_DIM_W                                          $32     !1, ~31
         35        ASSIGN_DIM                                                   $32
         36        OP_DATA                                                      !2
   30    37      > JMP                                                          ->12
         38    >   FE_FREE                                                      $18
   42    39        NEW                                                  $34     'DOMDocument'
         40        SEND_VAL_EX                                                  '1.0'
         41        SEND_VAL_EX                                                  'UTF-8'
         42        DO_FCALL                                          0          
         43        ASSIGN                                                       !5, $34
   43    44        INIT_METHOD_CALL                                             !5, 'appendChild'
         45        INIT_METHOD_CALL                                             !5, 'createElement'
         46        SEND_VAL_EX                                                  'root'
         47        DO_FCALL                                          0  $37     
         48        SEND_VAR_NO_REF_EX                                           $37
         49        DO_FCALL                                          0  $38     
         50        ASSIGN                                                       !6, $38
   44    51      > FE_RESET_R                                           $40     !1, ->86
         52    > > FE_FETCH_R                                           ~41     $40, !7, ->86
         53    >   ASSIGN                                                       !8, ~41
   45    54        INIT_METHOD_CALL                                             !6, 'appendChild'
         55        INIT_METHOD_CALL                                             !5, 'createElement'
         56        SEND_VAL_EX                                                  'product'
         57        DO_FCALL                                          0  $43     
         58        SEND_VAR_NO_REF_EX                                           $43
         59        DO_FCALL                                          0  $44     
         60        ASSIGN                                                       !9, $44
   46    61        INIT_METHOD_CALL                                             !9, 'appendChild'
         62        INIT_METHOD_CALL                                             !5, 'createElement'
         63        SEND_VAL_EX                                                  'title'
         64        SEND_VAR_EX                                                  !8
         65        DO_FCALL                                          0  $46     
         66        SEND_VAR_NO_REF_EX                                           $46
         67        DO_FCALL                                          0          
   47    68        ASSIGN                                                       !10, 0
         69      > JMP                                                          ->82
   48    70    >   INIT_METHOD_CALL                                             !9, 'appendChild'
         71        INIT_METHOD_CALL                                             !5, 'createElement'
         72        CONCAT                                               ~49     'category', !10
         73        SEND_VAL_EX                                                  ~49
         74        FETCH_DIM_R                                          ~50     !7, !10
         75        FETCH_DIM_R                                          ~51     ~50, 'category'
         76        FRAMELESS_ICALL_2                implode             ~52     '%2F%2F%2F', ~51
         77        SEND_VAL_EX                                                  ~52
         78        DO_FCALL                                          0  $53     
         79        SEND_VAR_NO_REF_EX                                           $53
         80        DO_FCALL                                          0          
   47    81        PRE_INC                                                      !10
         82    >   COUNT                                                ~56     !7
         83        IS_SMALLER                                                   !10, ~56
         84      > JMPNZ                                                        ~57, ->70
   44    85    > > JMP                                                          ->52
         86    >   FE_FREE                                                      $40
   51    87        ASSIGN_OBJ                                                   !5, 'formatOutput'
         88        OP_DATA                                                      <true>
   52    89        INIT_METHOD_CALL                                             !5, 'saveXML'
         90        DO_FCALL                                          0  $59     
         91        ECHO                                                         $59
         92      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
126.59 ms | 486 KiB | 8 Q