3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1, 4, 7, 20-25, 31, 46, 100'; $entries = array_map( 'trim', str_getcsv( $input)); $result = array(); foreach( $entries as $entry) { if( strpos( $entry, '-') !== false) { list( $start, $end) = explode( '-', $entry); $result = array_merge( $result, range( $start, $end)); } else { $result[] = $entry; } } print_r( $result); echo implode( ', ', $result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 40
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 40
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/Pn3SP
function name:  (null)
number of ops:  50
compiled vars:  !0 = $input, !1 = $entries, !2 = $result, !3 = $entry, !4 = $start, !5 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '1%2C+4%2C+7%2C+20-25%2C+31%2C+46%2C+100'
    3     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'trim'
          3        INIT_FCALL                                               'str_getcsv'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        SEND_VAR                                                 $7
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !1, $8
    5     9        ASSIGN                                                   !2, <array>
    6    10      > FE_RESET_R                                       $11     !1, ->40
         11    > > FE_FETCH_R                                               $11, !3, ->40
    7    12    >   INIT_FCALL                                               'strpos'
         13        SEND_VAR                                                 !3
         14        SEND_VAL                                                 '-'
         15        DO_ICALL                                         $12     
         16        TYPE_CHECK                                  1018          $12
         17      > JMPZ                                                     ~13, ->37
    8    18    >   INIT_FCALL                                               'explode'
         19        SEND_VAL                                                 '-'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $14     
         22        FETCH_LIST_R                                     $15     $14, 0
         23        ASSIGN                                                   !4, $15
         24        FETCH_LIST_R                                     $17     $14, 1
         25        ASSIGN                                                   !5, $17
         26        FREE                                                     $14
    9    27        INIT_FCALL                                               'array_merge'
         28        SEND_VAR                                                 !2
         29        INIT_FCALL                                               'range'
         30        SEND_VAR                                                 !4
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $19     
         33        SEND_VAR                                                 $19
         34        DO_ICALL                                         $20     
         35        ASSIGN                                                   !2, $20
         36      > JMP                                                      ->39
   11    37    >   ASSIGN_DIM                                               !2
         38        OP_DATA                                                  !3
    6    39    > > JMP                                                      ->11
         40    >   FE_FREE                                                  $11
   15    41        INIT_FCALL                                               'print_r'
         42        SEND_VAR                                                 !2
         43        DO_ICALL                                                 
   16    44        INIT_FCALL                                               'implode'
         45        SEND_VAL                                                 '%2C+'
         46        SEND_VAR                                                 !2
         47        DO_ICALL                                         $24     
         48        ECHO                                                     $24
         49      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.37 ms | 1400 KiB | 29 Q