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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.06 ms | 1400 KiB | 17 Q