3v4l.org

run code in 500+ PHP versions simultaneously
<?php define( 'PAIRS', [ [ 'mon,tue', 'tue,wed', 'wed,thu', 'thu,fri', 'fri,sat', 'sat,sun' ], [ 'mon-tue', 'tue-wed', 'wed-thu', 'thu-fri', 'fri-sat', 'sat-sun' ] ] ); function condenseDays(string $days): string { return preg_replace( '/-\K[^,]+-/', '', str_replace(PAIRS[0], PAIRS[1], $days) ); } 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/tEc6K
function name:  (null)
number of ops:  39
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'define'
    4     1        SEND_VAL                                                     'PAIRS'
    7     2        SEND_VAL                                                     <array>
    3     3        DO_ICALL                                                     
   33     4        INIT_FCALL                                                   'condensedays'
          5        SEND_VAL                                                     'mon%2Ctue%2Cwed%2Cthu%2Cfri%2Csat'
          6        DO_FCALL                                          0  $1      
          7        CONCAT                                               ~2      $1, '%0A'
          8        ECHO                                                         ~2
   34     9        INIT_FCALL                                                   'condensedays'
         10        SEND_VAL                                                     'tue%2Cthu%2Cfri%2Csun'
         11        DO_FCALL                                          0  $3      
         12        CONCAT                                               ~4      $3, '%0A'
         13        ECHO                                                         ~4
   35    14        INIT_FCALL                                                   'condensedays'
         15        SEND_VAL                                                     'mon%2Ctue%2Cwed%2Cfri%2Csat%2Csun'
         16        DO_FCALL                                          0  $5      
         17        CONCAT                                               ~6      $5, '%0A'
         18        ECHO                                                         ~6
   36    19        INIT_FCALL                                                   'condensedays'
         20        SEND_VAL                                                     'mon%2Cthu%2Csun'
         21        DO_FCALL                                          0  $7      
         22        CONCAT                                               ~8      $7, '%0A'
         23        ECHO                                                         ~8
   37    24        INIT_FCALL                                                   'condensedays'
         25        SEND_VAL                                                     'tue%2Cwed%2Cfri%2Csat'
         26        DO_FCALL                                          0  $9      
         27        CONCAT                                               ~10     $9, '%0A'
         28        ECHO                                                         ~10
   38    29        INIT_FCALL                                                   'condensedays'
         30        SEND_VAL                                                     'mon%2Cwed%2Cfri%2Csun'
         31        DO_FCALL                                          0  $11     
         32        CONCAT                                               ~12     $11, '%0A'
         33        ECHO                                                         ~12
   39    34        INIT_FCALL                                                   'condensedays'
         35        SEND_VAL                                                     'mon%2Ctue%2Cthu%2Cfri%2Csat%2Csun'
         36        DO_FCALL                                          0  $13     
         37        ECHO                                                         $13
         38      > RETURN                                                       1

Function condensedays:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tEc6K
function name:  condenseDays
number of ops:  13
compiled vars:  !0 = $days
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   RECV                                                 !0      
   30     1        FETCH_CONSTANT                                       ~1      'PAIRS'
          2        FETCH_DIM_R                                          ~2      ~1, 0
          3        FETCH_CONSTANT                                       ~3      'PAIRS'
          4        FETCH_DIM_R                                          ~4      ~3, 1
          5        FRAMELESS_ICALL_3                str_replace         ~5      ~2, ~4
          6        OP_DATA                                                      !0
   27     7        FRAMELESS_ICALL_3                preg_replace        ~6      '%2F-%5CK%5B%5E%2C%5D%2B-%2F', ''
   30     8        OP_DATA                                                      ~5
          9        VERIFY_RETURN_TYPE                                           ~6
         10      > RETURN                                                       ~6
   32    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null

End of function condensedays

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
180.07 ms | 1911 KiB | 21 Q