3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.61 ms | 1405 KiB | 15 Q