3v4l.org

run code in 300+ 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 = 36
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 36
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 = 34
Branch analysis from position: 34
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 = 31
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/eOVrP
function name:  condenseDays
number of ops:  41
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, ->36
          7    > > FE_FETCH_R                                               $6, !2, ->36
    9     8    >   BOOL_NOT                                         ~7      !1
          9      > JMPZ                                                     ~7, ->12
   10    10    >   ASSIGN_OP                                     8          !1, !2
    9    11      > JMP                                                      ->34
   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, ->31
   12    19    >   INIT_FCALL                                               'str_replace'
         20        NOP                                                      
         21        FAST_CONCAT                                      ~15     '-', !3
         22        SEND_VAL                                                 ~15
         23        SEND_VAL                                                 ''
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $16     
         26        NOP                                                      
         27        FAST_CONCAT                                      ~17     '-', !2
         28        CONCAT                                           ~18     $16, ~17
         29        ASSIGN                                                   !1, ~18
   11    30      > JMP                                                      ->34
   14    31    >   NOP                                                      
         32        FAST_CONCAT                                      ~20     '%2C', !2
         33        ASSIGN_OP                                     8          !1, ~20
   16    34    >   ASSIGN                                                   !3, !2
    8    35      > JMP                                                      ->7
         36    >   FE_FREE                                                  $6
   18    37        VERIFY_RETURN_TYPE                                       !1
         38      > RETURN                                                   !1
   19    39*       VERIFY_RETURN_TYPE                                       
         40*     > RETURN                                                   null

End of function condensedays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.72 ms | 1016 KiB | 24 Q