3v4l.org

run code in 500+ PHP versions simultaneously
<?php define('DAYS', array_flip(['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'])); function condenseDays(string $days): string { $result = ''; foreach (explode(',', $days) as $day) { if (!$result) { $result .= $day; } elseif (DAYS[$day] === DAYS[$yesterday] + 1) { $result = str_replace("-$yesterday", '', $result) . "-$day"; } else { $result .= ",$day"; } $yesterday = $day; } return $result; } echo condenseDays('mon,tue,wed,thu,fri,sat') . "\n"; echo condenseDays('tue,thu,fri,sun') . "\n"; echo condenseDays('mon,tue,wed,fri,sat,sun') . "\n"; echo condenseDays('mon,thu,sun') . "\n"; echo condenseDays('tue,wed,fri,sat') . "\n"; echo condenseDays('mon,wed,fri,sun') . "\n"; echo condenseDays('mon,tue,thu,fri,sat,sun');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eOVrP
function name:  (null)
number of ops:  42
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'DAYS'
          2        INIT_FCALL                                                   'array_flip'
          3        SEND_VAL                                                     <array>
          4        DO_ICALL                                             $0      
          5        SEND_VAR                                                     $0
          6        DO_ICALL                                                     
   20     7        INIT_FCALL                                                   'condensedays'
          8        SEND_VAL                                                     'mon%2Ctue%2Cwed%2Cthu%2Cfri%2Csat'
          9        DO_FCALL                                          0  $2      
         10        CONCAT                                               ~3      $2, '%0A'
         11        ECHO                                                         ~3
   21    12        INIT_FCALL                                                   'condensedays'
         13        SEND_VAL                                                     'tue%2Cthu%2Cfri%2Csun'
         14        DO_FCALL                                          0  $4      
         15        CONCAT                                               ~5      $4, '%0A'
         16        ECHO                                                         ~5
   22    17        INIT_FCALL                                                   'condensedays'
         18        SEND_VAL                                                     'mon%2Ctue%2Cwed%2Cfri%2Csat%2Csun'
         19        DO_FCALL                                          0  $6      
         20        CONCAT                                               ~7      $6, '%0A'
         21        ECHO                                                         ~7
   23    22        INIT_FCALL                                                   'condensedays'
         23        SEND_VAL                                                     'mon%2Cthu%2Csun'
         24        DO_FCALL                                          0  $8      
         25        CONCAT                                               ~9      $8, '%0A'
         26        ECHO                                                         ~9
   24    27        INIT_FCALL                                                   'condensedays'
         28        SEND_VAL                                                     'tue%2Cwed%2Cfri%2Csat'
         29        DO_FCALL                                          0  $10     
         30        CONCAT                                               ~11     $10, '%0A'
         31        ECHO                                                         ~11
   25    32        INIT_FCALL                                                   'condensedays'
         33        SEND_VAL                                                     'mon%2Cwed%2Cfri%2Csun'
         34        DO_FCALL                                          0  $12     
         35        CONCAT                                               ~13     $12, '%0A'
         36        ECHO                                                         ~13
   26    37        INIT_FCALL                                                   'condensedays'
         38        SEND_VAL                                                     'mon%2Ctue%2Cthu%2Cfri%2Csat%2Csun'
         39        DO_FCALL                                          0  $14     
         40        ECHO                                                         $14
         41      > RETURN                                                       1

Function condensedays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/eOVrP
function name:  condenseDays
number of ops:  38
compiled vars:  !0 = $days, !1 = $result, !2 = $day, !3 = $yesterday
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
    7     1        ASSIGN                                                       !1, ''
    8     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '%2C'
          4        SEND_VAR                                                     !0
          5        DO_ICALL                                             $5      
          6      > FE_RESET_R                                           $6      $5, ->33
          7    > > FE_FETCH_R                                                   $6, !2, ->33
    9     8    >   BOOL_NOT                                             ~7      !1
          9      > JMPZ                                                         ~7, ->12
   10    10    >   ASSIGN_OP                                         8          !1, !2
    9    11      > JMP                                                          ->31
   11    12    >   FETCH_CONSTANT                                       ~9      'DAYS'
         13        FETCH_DIM_R                                          ~10     ~9, !2
         14        FETCH_CONSTANT                                       ~11     'DAYS'
         15        FETCH_DIM_R                                          ~12     ~11, !3
         16        ADD                                                  ~13     ~12, 1
         17        IS_IDENTICAL                                                 ~10, ~13
         18      > JMPZ                                                         ~14, ->28
   12    19    >   NOP                                                          
         20        FAST_CONCAT                                          ~15     '-', !3
         21        FRAMELESS_ICALL_3                str_replace         ~16     ~15, ''
         22        OP_DATA                                                      !1
         23        NOP                                                          
         24        FAST_CONCAT                                          ~17     '-', !2
         25        CONCAT                                               ~18     ~16, ~17
         26        ASSIGN                                                       !1, ~18
   11    27      > JMP                                                          ->31
   14    28    >   NOP                                                          
         29        FAST_CONCAT                                          ~20     '%2C', !2
         30        ASSIGN_OP                                         8          !1, ~20
   16    31    >   ASSIGN                                                       !3, !2
    8    32      > JMP                                                          ->7
         33    >   FE_FREE                                                      $6
   18    34        VERIFY_RETURN_TYPE                                           !1
         35      > RETURN                                                       !1
   19    36*       VERIFY_RETURN_TYPE                                           
         37*     > RETURN                                                       null

End of function condensedays

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
199.65 ms | 1917 KiB | 23 Q