3v4l.org

run code in 300+ PHP versions simultaneously
<?php $numbers = [1, 2, 3, 4, 5, 6, 7, 11, 21, 22, 23, 24]; $numbers = [1, 3, 5, 6, 11, 21, 22, 23, 24, 26]; $prev = -1; foreach ($numbers as $n) { if (!isset($start)) { $start = $n; } elseif ($n != $prev + 1) { $result[] = $start == $prev ? $prev : "$start-$prev"; $start = $n; } $prev = $n; } $result[] = $start == $prev ? $prev : $start . '-' . $prev; echo implode(', ', $result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/sp8Eh
function name:  (null)
number of ops:  42
compiled vars:  !0 = $numbers, !1 = $prev, !2 = $n, !3 = $start, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !0, <array>
    5     2        ASSIGN                                                   !1, -1
    6     3      > FE_RESET_R                                       $8      !0, ->26
          4    > > FE_FETCH_R                                               $8, !2, ->26
    7     5    >   ISSET_ISEMPTY_CV                                 ~9      !3
          6        BOOL_NOT                                         ~10     ~9
          7      > JMPZ                                                     ~10, ->10
    8     8    >   ASSIGN                                                   !3, !2
          9      > JMP                                                      ->24
    9    10    >   ADD                                              ~12     !1, 1
         11        IS_NOT_EQUAL                                             !2, ~12
         12      > JMPZ                                                     ~13, ->24
   10    13    >   IS_EQUAL                                                 !3, !1
         14      > JMPZ                                                     ~15, ->17
         15    >   QM_ASSIGN                                        ~16     !1
         16      > JMP                                                      ->21
         17    >   ROPE_INIT                                     3  ~18     !3
         18        ROPE_ADD                                      1  ~18     ~18, '-'
         19        ROPE_END                                      2  ~17     ~18, !1
         20        QM_ASSIGN                                        ~16     ~17
         21    >   ASSIGN_DIM                                               !4
         22        OP_DATA                                                  ~16
   11    23        ASSIGN                                                   !3, !2
   13    24    >   ASSIGN                                                   !1, !2
    6    25      > JMP                                                      ->4
         26    >   FE_FREE                                                  $8
   15    27        IS_EQUAL                                                 !3, !1
         28      > JMPZ                                                     ~23, ->31
         29    >   QM_ASSIGN                                        ~24     !1
         30      > JMP                                                      ->34
         31    >   CONCAT                                           ~25     !3, '-'
         32        CONCAT                                           ~26     ~25, !1
         33        QM_ASSIGN                                        ~24     ~26
         34    >   ASSIGN_DIM                                               !4
         35        OP_DATA                                                  ~24
   16    36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '%2C+'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $27     
         40        ECHO                                                     $27
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.5 ms | 1404 KiB | 15 Q