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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.83 ms | 1392 KiB | 15 Q