3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1_2_3_4_5'; // Get an array with 1, 2, 3, 4 and 5 $parts = explode('_', $input); $output = []; $i = 1; foreach ($parts as $part) { // array_slice() will take 1 to n elements from the array of numbers $values = array_slice($parts, 0, $i++); // Join the values $output[] = implode('_', $values); } print_r($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 24
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/lUWD2
function name:  (null)
number of ops:  29
compiled vars:  !0 = $input, !1 = $parts, !2 = $output, !3 = $i, !4 = $part, !5 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '1_2_3_4_5'
    6     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '_'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
    8     6        ASSIGN                                                   !2, <array>
   10     7        ASSIGN                                                   !3, 1
   12     8      > FE_RESET_R                                       $11     !1, ->24
          9    > > FE_FETCH_R                                               $11, !4, ->24
   14    10    >   INIT_FCALL                                               'array_slice'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 0
         13        POST_INC                                         ~12     !3
         14        SEND_VAL                                                 ~12
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !5, $13
   16    17        INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '_'
         19        SEND_VAR                                                 !5
         20        DO_ICALL                                         $16     
         21        ASSIGN_DIM                                               !2
         22        OP_DATA                                                  $16
   12    23      > JMP                                                      ->9
         24    >   FE_FREE                                                  $11
   19    25        INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.3 ms | 1396 KiB | 21 Q