3v4l.org

run code in 500+ PHP versions simultaneously
<?php $chars = ['A','B','C','F','a','b','c','d','e','f','h','i','j','k','l','o','q','!','?','0','2','3','4','9']; $result = []; $range = [null]; foreach ($chars as $char) { if ($range[0] === null) { $range = [$char]; } elseif (ord($range[1] ?? $range[0]) === ord($char) - 1) { $range[1] = $char; } else { $result[] = implode('-', $range); $range = [$char]; } } if ($range[0] !== null) { $result[] = implode('-', $range); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 33
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 33
filename:       /in/trGMC
function name:  (null)
number of ops:  44
compiled vars:  !0 = $chars, !1 = $result, !2 = $range, !3 = $char
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        ASSIGN                                                       !1, <array>
    6     2        ASSIGN                                                       !2, <array>
    7     3      > FE_RESET_R                                           $7      !0, ->33
          4    > > FE_FETCH_R                                                   $7, !3, ->33
    8     5    >   FETCH_DIM_R                                          ~8      !2, 0
          6        TYPE_CHECK                                        2          ~8
          7      > JMPZ                                                         ~9, ->11
    9     8    >   INIT_ARRAY                                           ~10     !3
          9        ASSIGN                                                       !2, ~10
    8    10      > JMP                                                          ->32
   10    11    >   INIT_FCALL                                                   'ord'
         12        FETCH_DIM_IS                                         ~12     !2, 1
         13        COALESCE                                             ~13     ~12
         14        FETCH_DIM_R                                          ~14     !2, 0
         15        QM_ASSIGN                                            ~13     ~14
         16        SEND_VAL                                                     ~13
         17        DO_ICALL                                             $15     
         18        INIT_FCALL                                                   'ord'
         19        SEND_VAR                                                     !3
         20        DO_ICALL                                             $16     
         21        SUB                                                  ~17     $16, 1
         22        IS_IDENTICAL                                                 $15, ~17
         23      > JMPZ                                                         ~18, ->27
   11    24    >   ASSIGN_DIM                                                   !2, 1
         25        OP_DATA                                                      !3
   10    26      > JMP                                                          ->32
   13    27    >   FRAMELESS_ICALL_2                implode             ~21     '-', !2
         28        ASSIGN_DIM                                                   !1
         29        OP_DATA                                                      ~21
   14    30        INIT_ARRAY                                           ~22     !3
         31        ASSIGN                                                       !2, ~22
    7    32    > > JMP                                                          ->4
         33    >   FE_FREE                                                      $7
   17    34        FETCH_DIM_R                                          ~24     !2, 0
         35        TYPE_CHECK                                      1020          ~24
         36      > JMPZ                                                         ~25, ->40
   18    37    >   FRAMELESS_ICALL_2                implode             ~27     '-', !2
         38        ASSIGN_DIM                                                   !1
         39        OP_DATA                                                      ~27
   20    40    >   INIT_FCALL                                                   'var_export'
         41        SEND_VAR                                                     !1
         42        DO_ICALL                                                     
         43      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.79 ms | 1913 KiB | 15 Q