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) ?: ''; $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 = 45
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 45
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 44
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 26
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 26
Branch analysis from position: 44
Branch analysis from position: 26
Branch analysis from position: 44
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/fRaDb
function name:  (null)
number of ops:  50
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, ->45
          6    > > FE_FETCH_R                                               $8, !1, ->45
   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, ->44
   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                                                      ->39
   27    26    >   CONCAT                                           ~20     'image', !3
         27        JMP_SET                                          ~21     ~20, ->29
         28        QM_ASSIGN                                        ~21     ''
         29        ASSIGN                                                   !4, ~21
   29    30        FETCH_OBJ_R                                      ~23     !1, 'images'
         31        INIT_METHOD_CALL                                         ~23, 'addChild'
         32        SEND_VAR_EX                                              !4
         33        CHECK_FUNC_ARG                                           
         34        FETCH_OBJ_FUNC_ARG                               $24     !2, 'image'
         35        FETCH_DIM_FUNC_ARG                               $25     $24, !3
         36        SEND_FUNC_ARG                                            $25
         37        DO_FCALL                                      0          
   26    38        PRE_INC                                                  !3
         39    >   FETCH_OBJ_R                                      ~28     !2, 'image'
         40        INIT_METHOD_CALL                                         ~28, 'count'
         41        DO_FCALL                                      0  $29     
         42        IS_SMALLER                                               !3, $29
         43      > JMPNZ                                                    ~30, ->26
   16    44    > > JMP                                                      ->6
         45    >   FE_FREE                                                  $8
   35    46        INIT_METHOD_CALL                                         !0, 'asXML'
         47        DO_FCALL                                      0  $31     
         48        ECHO                                                     $31
         49      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.5 ms | 1400 KiB | 17 Q