3v4l.org

run code in 300+ 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:  19
compiled vars:  !0 = $days
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        INIT_FCALL                                               'preg_replace'
   28     2        SEND_VAL                                                 '%2F-%5CK%5B%5E%2C%5D%2B-%2F'
   29     3        SEND_VAL                                                 ''
   30     4        INIT_FCALL                                               'str_replace'
          5        FETCH_CONSTANT                                   ~1      'PAIRS'
          6        FETCH_DIM_R                                      ~2      ~1, 0
          7        SEND_VAL                                                 ~2
          8        FETCH_CONSTANT                                   ~3      'PAIRS'
          9        FETCH_DIM_R                                      ~4      ~3, 1
         10        SEND_VAL                                                 ~4
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $5      
         13        SEND_VAR                                                 $5
   27    14        DO_ICALL                                         $6      
   30    15        VERIFY_RETURN_TYPE                                       $6
         16      > RETURN                                                   $6
   32    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function condensedays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.92 ms | 1011 KiB | 23 Q