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); for ($i = 0; $i < $images->image->count(); $i++) { $name = 'image' . ($i > 0) ? $i : ''; $item->images->addChild($name, $images->image[$i]); } } } //$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 = 48
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 48
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 47
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 26
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 26
Branch analysis from position: 47
Branch analysis from position: 26
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 26
Branch analysis from position: 47
Branch analysis from position: 26
Branch analysis from position: 47
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/rasCb
function name:  (null)
number of ops:  53
compiled vars:  !0 = $xml, !1 = $item, !2 = $images, !3 = $i, !4 = $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                                         $5      
          3        ASSIGN                                                   !0, $5
   16     4        FETCH_OBJ_R                                      ~7      !0, 'item'
          5      > FE_RESET_R                                       $8      ~7, ->48
          6    > > FE_FETCH_R                                               $8, !1, ->48
   17     7    >   FETCH_OBJ_R                                      ~9      !1, 'images'
          8        FETCH_OBJ_R                                      ~10     ~9, 'image'
          9        INIT_METHOD_CALL                                         ~10, 'count'
         10        DO_FCALL                                      0  $11     
         11        IS_SMALLER                                               1, $11
         12      > JMPZ                                                     ~12, ->47
   19    13    >   FETCH_OBJ_R                                      ~13     !1, 'images'
         14        CLONE                                            ~14     ~13
         15        ASSIGN                                                   !2, ~14
   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                                      ~17     !2, 'image'
         22        SEND_VAL                                                 ~17
         23        DO_ICALL                                                 
   26    24        ASSIGN                                                   !3, 0
         25      > JMP                                                      ->42
   27    26    >   IS_SMALLER                                       ~20     0, !3
         27        CONCAT                                           ~21     'image', ~20
         28      > JMPZ                                                     ~21, ->31
         29    >   QM_ASSIGN                                        ~22     !3
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~22     ''
         32    >   ASSIGN                                                   !4, ~22
   28    33        FETCH_OBJ_R                                      ~24     !1, 'images'
         34        INIT_METHOD_CALL                                         ~24, 'addChild'
         35        SEND_VAR_EX                                              !4
         36        CHECK_FUNC_ARG                                           
         37        FETCH_OBJ_FUNC_ARG                               $25     !2, 'image'
         38        FETCH_DIM_FUNC_ARG                               $26     $25, !3
         39        SEND_FUNC_ARG                                            $26
         40        DO_FCALL                                      0          
   26    41        PRE_INC                                                  !3
         42    >   FETCH_OBJ_R                                      ~29     !2, 'image'
         43        INIT_METHOD_CALL                                         ~29, 'count'
         44        DO_FCALL                                      0  $30     
         45        IS_SMALLER                                               !3, $30
         46      > JMPNZ                                                    ~31, ->26
   16    47    > > JMP                                                      ->6
         48    >   FE_FREE                                                  $8
   34    49        INIT_METHOD_CALL                                         !0, 'asXML'
         50        DO_FCALL                                      0  $32     
         51        ECHO                                                     $32
         52      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.19 ms | 1400 KiB | 17 Q