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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.18 ms | 1400 KiB | 17 Q