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) ?: ''; var_dump($key); $item->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 = 39
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 39
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 38
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 37
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 37
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 37
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/ibp4l
function name:  (null)
number of ops:  44
compiled vars:  !0 = $xml, !1 = $item, !2 = $images, !3 = $img, !4 = $key, !5 = $name
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                                         $6      
          3        ASSIGN                                                   !0, $6
   16     4        FETCH_OBJ_R                                      ~8      !0, 'item'
          5      > FE_RESET_R                                       $9      ~8, ->39
          6    > > FE_FETCH_R                                               $9, !1, ->39
   17     7    >   FETCH_OBJ_R                                      ~10     !1, 'images'
          8        FETCH_OBJ_R                                      ~11     ~10, 'image'
          9        INIT_METHOD_CALL                                         ~11, 'count'
         10        DO_FCALL                                      0  $12     
         11        IS_SMALLER                                               1, $12
         12      > JMPZ                                                     ~13, ->38
   19    13    >   FETCH_OBJ_R                                      ~14     !1, 'images'
         14        CLONE                                            ~15     ~14
         15        ASSIGN                                                   !2, ~15
   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                                      ~18     !2, 'image'
         21      > FE_RESET_R                                       $19     ~18, ->37
         22    > > FE_FETCH_R                                       ~20     $19, !3, ->37
         23    >   ASSIGN                                                   !4, ~20
   26    24        CONCAT                                           ~22     'image', !4
         25        JMP_SET                                          ~23     ~22, ->27
         26        QM_ASSIGN                                        ~23     ''
         27        ASSIGN                                                   !5, ~23
   27    28        INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                                 
   28    31        FETCH_OBJ_R                                      ~26     !1, 'images'
         32        INIT_METHOD_CALL                                         ~26, 'addChild'
         33        SEND_VAR_EX                                              !5
         34        SEND_VAR_EX                                              !3
         35        DO_FCALL                                      0          
   25    36      > JMP                                                      ->22
         37    >   FE_FREE                                                  $19
   16    38    > > JMP                                                      ->6
         39    >   FE_FREE                                                  $9
   34    40        INIT_METHOD_CALL                                         !0, 'asXML'
         41        DO_FCALL                                      0  $28     
         42        ECHO                                                     $28
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.6 ms | 1400 KiB | 17 Q