3v4l.org

run code in 300+ PHP versions simultaneously
<?php function compound(array $arr) { $cache=array(); $rst=""; foreach($arr as $v) { if(empty($cache) || $v==end($cache)+1) { $cache[]=$v; } else { if(!empty($rst)) $rst.=","; if(count($cache)>2) $rst.=reset($cache)."-".end($cache); else $rst.=implode(",",$cache); $cache=array($v); } } if(!empty($rst)) $rst.=","; if(count($cache)>2) $rst.=reset($cache)."-".end($cache); else $rst.=implode(",",$cache); return $rst; } echo compound(array(1,2,3,5,6))."\n"; // gets "1-3,5,6" echo compound(array(1,3,4,5,6)); // gets "1,3-6"
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/untCF
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'compound'
          1        SEND_VAL                                                 <array>
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   26     5        INIT_FCALL                                               'compound'
          6        SEND_VAL                                                 <array>
          7        DO_FCALL                                      0  $2      
          8        ECHO                                                     $2
          9      > RETURN                                                   1

Function compound:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 42
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 42
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 34
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
Branch analysis from position: 13
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 60
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 42
filename:       /in/untCF
function name:  compound
number of ops:  67
compiled vars:  !0 = $arr, !1 = $cache, !2 = $rst, !3 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, ''
    6     3      > FE_RESET_R                                       $6      !0, ->42
          4    > > FE_FETCH_R                                               $6, !3, ->42
    8     5    >   ISSET_ISEMPTY_CV                                 ~7      !1
          6      > JMPNZ_EX                                         ~7      ~7, ->13
          7    >   INIT_FCALL                                               'end'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $8      
         10        ADD                                              ~9      $8, 1
         11        IS_EQUAL                                         ~10     !3, ~9
         12        BOOL                                             ~7      ~10
         13    > > JMPZ                                                     ~7, ->17
   10    14    >   ASSIGN_DIM                                               !1
         15        OP_DATA                                                  !3
         16      > JMP                                                      ->41
   14    17    >   ISSET_ISEMPTY_CV                                 ~12     !2
         18        BOOL_NOT                                         ~13     ~12
         19      > JMPZ                                                     ~13, ->21
         20    >   ASSIGN_OP                                     8          !2, '%2C'
   15    21    >   COUNT                                            ~15     !1
         22        IS_SMALLER                                               2, ~15
         23      > JMPZ                                                     ~16, ->34
         24    >   INIT_FCALL                                               'reset'
         25        SEND_REF                                                 !1
         26        DO_ICALL                                         $17     
         27        CONCAT                                           ~18     $17, '-'
         28        INIT_FCALL                                               'end'
         29        SEND_REF                                                 !1
         30        DO_ICALL                                         $19     
         31        CONCAT                                           ~20     ~18, $19
         32        ASSIGN_OP                                     8          !2, ~20
         33      > JMP                                                      ->39
   16    34    >   INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '%2C'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                         $22     
         38        ASSIGN_OP                                     8          !2, $22
   17    39    >   INIT_ARRAY                                       ~24     !3
         40        ASSIGN                                                   !1, ~24
    6    41    > > JMP                                                      ->4
         42    >   FE_FREE                                                  $6
   20    43        ISSET_ISEMPTY_CV                                 ~26     !2
         44        BOOL_NOT                                         ~27     ~26
         45      > JMPZ                                                     ~27, ->47
         46    >   ASSIGN_OP                                     8          !2, '%2C'
   21    47    >   COUNT                                            ~29     !1
         48        IS_SMALLER                                               2, ~29
         49      > JMPZ                                                     ~30, ->60
         50    >   INIT_FCALL                                               'reset'
         51        SEND_REF                                                 !1
         52        DO_ICALL                                         $31     
         53        CONCAT                                           ~32     $31, '-'
         54        INIT_FCALL                                               'end'
         55        SEND_REF                                                 !1
         56        DO_ICALL                                         $33     
         57        CONCAT                                           ~34     ~32, $33
         58        ASSIGN_OP                                     8          !2, ~34
         59      > JMP                                                      ->65
   22    60    >   INIT_FCALL                                               'implode'
         61        SEND_VAL                                                 '%2C'
         62        SEND_VAR                                                 !1
         63        DO_ICALL                                         $36     
         64        ASSIGN_OP                                     8          !2, $36
   23    65    > > RETURN                                                   !2
   24    66*     > RETURN                                                   null

End of function compound

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.12 ms | 1407 KiB | 21 Q