3v4l.org

run code in 300+ PHP versions simultaneously
<?php function group_nums($array) { $ret = array(); $temp = array(); foreach($array as $val) { if(next($array) == ($val + 1)) $temp[] = $val; else if(count($temp) > 0) { $temp[] = $val; $ret[] = $temp[0].'-'.end($temp); $temp = array(); } else $ret[] = $val; } return $ret; } $a = [2,3,4,7,8,9,10,11,13,15]; print_r(group_num($a));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KO7fI
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL_BY_NAME                                       'group_num'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function group_nums:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 32
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 32
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 29
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/KO7fI
function name:  group_nums
number of ops:  35
compiled vars:  !0 = $array, !1 = $ret, !2 = $temp, !3 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    4     2        ASSIGN                                                   !2, <array>
    5     3      > FE_RESET_R                                       $6      !0, ->32
          4    > > FE_FETCH_R                                               $6, !3, ->32
    6     5    >   INIT_FCALL                                               'next'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                         $7      
          8        ADD                                              ~8      !3, 1
          9        IS_EQUAL                                                 $7, ~8
         10      > JMPZ                                                     ~9, ->14
    7    11    >   ASSIGN_DIM                                               !2
         12        OP_DATA                                                  !3
         13      > JMP                                                      ->31
    9    14    >   COUNT                                            ~11     !2
         15        IS_SMALLER                                               0, ~11
         16      > JMPZ                                                     ~12, ->29
   10    17    >   ASSIGN_DIM                                               !2
         18        OP_DATA                                                  !3
   11    19        FETCH_DIM_R                                      ~15     !2, 0
         20        CONCAT                                           ~16     ~15, '-'
         21        INIT_FCALL                                               'end'
         22        SEND_REF                                                 !2
         23        DO_ICALL                                         $17     
         24        CONCAT                                           ~18     ~16, $17
         25        ASSIGN_DIM                                               !1
         26        OP_DATA                                                  ~18
   12    27        ASSIGN                                                   !2, <array>
         28      > JMP                                                      ->31
   15    29    >   ASSIGN_DIM                                               !1
         30        OP_DATA                                                  !3
    5    31    > > JMP                                                      ->4
         32    >   FE_FREE                                                  $6
   17    33      > RETURN                                                   !1
   18    34*     > RETURN                                                   null

End of function group_nums

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.69 ms | 1392 KiB | 19 Q