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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.82 ms | 1392 KiB | 15 Q