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'); var_dump($images->image); foreach ($images->image as $key => $img ) { var_dump($key,$img); $name = 'image' . ($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 = 44
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 44
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 43
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 42
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 42
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 42
Branch analysis from position: 43
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/OZPI0
function name:  (null)
number of ops:  49
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, ->44
          6    > > FE_FETCH_R                                               $9, !1, ->44
   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, ->43
   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        INIT_FCALL                                               'var_dump'
         21        FETCH_OBJ_R                                      ~18     !2, 'image'
         22        SEND_VAL                                                 ~18
         23        DO_ICALL                                                 
   26    24        FETCH_OBJ_R                                      ~20     !2, 'image'
         25      > FE_RESET_R                                       $21     ~20, ->42
         26    > > FE_FETCH_R                                       ~22     $21, !3, ->42
         27    >   ASSIGN                                                   !4, ~22
   27    28        INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !4
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                                 
   28    32        CONCAT                                           ~25     'image', !4
         33        JMP_SET                                          ~26     ~25, ->35
         34        QM_ASSIGN                                        ~26     ''
         35        ASSIGN                                                   !5, ~26
   30    36        FETCH_OBJ_R                                      ~28     !1, 'images'
         37        INIT_METHOD_CALL                                         ~28, 'addChild'
         38        SEND_VAR_EX                                              !5
         39        SEND_VAR_EX                                              !3
         40        DO_FCALL                                      0          
   26    41      > JMP                                                      ->26
         42    >   FE_FREE                                                  $21
   16    43    > > JMP                                                      ->6
         44    >   FE_FREE                                                  $9
   36    45        INIT_METHOD_CALL                                         !0, 'asXML'
         46        DO_FCALL                                      0  $30     
         47        ECHO                                                     $30
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.64 ms | 1392 KiB | 17 Q