3v4l.org

run code in 500+ 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:  9
compiled vars:  !0 = $days
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    8     1        FRAMELESS_ICALL_3                str_replace         ~1      <array>, <array>
   11     2        OP_DATA                                                      !0
    5     3        FRAMELESS_ICALL_3                preg_replace        ~2      '%2F-%5CK%5B%5E%2C%5D%2B-%2F', ''
   11     4        OP_DATA                                                      ~1
          5        VERIFY_RETURN_TYPE                                           ~2
          6      > RETURN                                                       ~2
   14     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function condensedays

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.96 ms | 1909 KiB | 20 Q