3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$xml = simplexml_load_file('data.xml'); $xml = simplexml_load_string('<items> <item> <images> <image>A</image> <image>B</image> <image>C</image> </images> </item> </items>'); //var_dump($xml); // Loop over items in original xml foreach ($xml->item as $item) { if ($item->images->image->count() > 1) { // Clone entry $images = clone $item->images; // Remove entry and replace with empty unset($item->images); $item->addChild('images'); foreach ($images->image as $key => $img ) { $name = 'image' . ($key) ?: ''; $xml->item[$i]->images->addChild($name, $img); } } } //$xml->asXML('POTO.xml'); echo $xml->asXML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 38
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 38
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 37
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 36
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 36
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 36
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/Je1Af
function name:  (null)
number of ops:  43
compiled vars:  !0 = $xml, !1 = $item, !2 = $images, !3 = $img, !4 = $key, !5 = $name, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'simplexml_load_string'
          1        SEND_VAL                                                 '%3Citems%3E%0A++%3Citem%3E%0A++++%3Cimages%3E%0A++++++%3Cimage%3EA%3C%2Fimage%3E%0A++++++%3Cimage%3EB%3C%2Fimage%3E%0A++++++%3Cimage%3EC%3C%2Fimage%3E%0A++++%3C%2Fimages%3E%0A++%3C%2Fitem%3E%0A%3C%2Fitems%3E'
          2        DO_ICALL                                         $7      
          3        ASSIGN                                                   !0, $7
   16     4        FETCH_OBJ_R                                      ~9      !0, 'item'
          5      > FE_RESET_R                                       $10     ~9, ->38
          6    > > FE_FETCH_R                                               $10, !1, ->38
   17     7    >   FETCH_OBJ_R                                      ~11     !1, 'images'
          8        FETCH_OBJ_R                                      ~12     ~11, 'image'
          9        INIT_METHOD_CALL                                         ~12, 'count'
         10        DO_FCALL                                      0  $13     
         11        IS_SMALLER                                               1, $13
         12      > JMPZ                                                     ~14, ->37
   19    13    >   FETCH_OBJ_R                                      ~15     !1, 'images'
         14        CLONE                                            ~16     ~15
         15        ASSIGN                                                   !2, ~16
   22    16        UNSET_OBJ                                                !1, 'images'
   23    17        INIT_METHOD_CALL                                         !1, 'addChild'
         18        SEND_VAL_EX                                              'images'
         19        DO_FCALL                                      0          
   25    20        FETCH_OBJ_R                                      ~19     !2, 'image'
         21      > FE_RESET_R                                       $20     ~19, ->36
         22    > > FE_FETCH_R                                       ~21     $20, !3, ->36
         23    >   ASSIGN                                                   !4, ~21
   26    24        CONCAT                                           ~23     'image', !4
         25        JMP_SET                                          ~24     ~23, ->27
         26        QM_ASSIGN                                        ~24     ''
         27        ASSIGN                                                   !5, ~24
   27    28        FETCH_OBJ_R                                      ~26     !0, 'item'
         29        FETCH_DIM_R                                      ~27     ~26, !6
         30        FETCH_OBJ_R                                      ~28     ~27, 'images'
         31        INIT_METHOD_CALL                                         ~28, 'addChild'
         32        SEND_VAR_EX                                              !5
         33        SEND_VAR_EX                                              !3
         34        DO_FCALL                                      0          
   25    35      > JMP                                                      ->22
         36    >   FE_FREE                                                  $20
   16    37    > > JMP                                                      ->6
         38    >   FE_FREE                                                  $10
   33    39        INIT_METHOD_CALL                                         !0, 'asXML'
         40        DO_FCALL                                      0  $30     
         41        ECHO                                                     $30
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.97 ms | 1400 KiB | 15 Q