3v4l.org

run code in 300+ PHP versions simultaneously
<?php function condenseDays(string $days): string { return preg_replace( '/-\K[^,]+-/', '', str_replace( ['n,t', 'e,w', 'd,t', 'u,f', 'i,s', 't,s'], ['n-t', 'e-w', 'd-t', 'u-f', 'i-s', 't-s'], $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/KlRKO
function name:  (null)
number of ops:  35
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'condensedays'
          1        SEND_VAL                                                 'mon%2Ctue%2Cwed%2Cthu%2Cfri%2Csat'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   16     5        INIT_FCALL                                               'condensedays'
          6        SEND_VAL                                                 'tue%2Cthu%2Cfri%2Csun'
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   17    10        INIT_FCALL                                               'condensedays'
         11        SEND_VAL                                                 'mon%2Ctue%2Cwed%2Cfri%2Csat%2Csun'
         12        DO_FCALL                                      0  $4      
         13        CONCAT                                           ~5      $4, '%0A'
         14        ECHO                                                     ~5
   18    15        INIT_FCALL                                               'condensedays'
         16        SEND_VAL                                                 'mon%2Cthu%2Csun'
         17        DO_FCALL                                      0  $6      
         18        CONCAT                                           ~7      $6, '%0A'
         19        ECHO                                                     ~7
   19    20        INIT_FCALL                                               'condensedays'
         21        SEND_VAL                                                 'tue%2Cwed%2Cfri%2Csat'
         22        DO_FCALL                                      0  $8      
         23        CONCAT                                           ~9      $8, '%0A'
         24        ECHO                                                     ~9
   20    25        INIT_FCALL                                               'condensedays'
         26        SEND_VAL                                                 'mon%2Cwed%2Cfri%2Csun'
         27        DO_FCALL                                      0  $10     
         28        CONCAT                                           ~11     $10, '%0A'
         29        ECHO                                                     ~11
   21    30        INIT_FCALL                                               'condensedays'
         31        SEND_VAL                                                 'mon%2Ctue%2Cthu%2Cfri%2Csat%2Csun'
         32        DO_FCALL                                      0  $12     
         33        ECHO                                                     $12
         34      > RETURN                                                   1

Function condensedays:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KlRKO
function name:  condenseDays
number of ops:  15
compiled vars:  !0 = $days
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_replace'
    6     2        SEND_VAL                                                 '%2F-%5CK%5B%5E%2C%5D%2B-%2F'
    7     3        SEND_VAL                                                 ''
    8     4        INIT_FCALL                                               'str_replace'
    9     5        SEND_VAL                                                 <array>
   10     6        SEND_VAL                                                 <array>
   11     7        SEND_VAR                                                 !0
    8     8        DO_ICALL                                         $1      
   11     9        SEND_VAR                                                 $1
    5    10        DO_ICALL                                         $2      
   11    11        VERIFY_RETURN_TYPE                                       $2
         12      > RETURN                                                   $2
   14    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function condensedays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.3 ms | 1010 KiB | 22 Q