3v4l.org

run code in 300+ PHP versions simultaneously
<?php $showtimes = [ "2014-01-20 20:00:00", "2014-01-21 20:00:00", "2014-01-22 14:00:00", "2014-01-22 20:00:00", "2014-01-23 20:00:00", "2014-01-25 20:00:00", "2014-01-26 20:00:00", "2014-01-31 20:00:00", "2014-02-01 20:00:00" ]; // 20th-23rd Jan 8pm, 22nd Jan 2pm, 25th-26th Jan 8pm, 31st Jan - 1st Feb 8pm foreach ($showtimes as $showtime) { $dt = new DateTime($showtime); $thisDay = $dt->format('Y-m-d H:i:s'); $nextDay = (clone $dt)->modify('+1 day')->format('Y-m-d H:i:s'); if (!isset($ref[$thisDay])) { $ref[$nextDay] = $dt->format('jS M ga'); $result[] =& $ref[$nextDay]; continue; } // if same month if (str_contains($ref[$thisDay], $dt->format('M'))) { // inject day $ref[$thisDay] = preg_replace( '/[tdh]\b\K[^ ]*/', $dt->format('-jS'), $ref[$thisDay] ); } else { // inject day and month $ref[$thisDay] = preg_replace( '/ (?=[^ ]*$)/', $dt->format(' - jS M '), $ref[$thisDay] ); } $ref[$nextDay] =& $ref[$thisDay]; } echo implode(', ', $result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 69
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 69
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 32
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 53
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
filename:       /in/KLbNf
function name:  (null)
number of ops:  76
compiled vars:  !0 = $showtimes, !1 = $showtime, !2 = $dt, !3 = $thisDay, !4 = $nextDay, !5 = $ref, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1      > FE_RESET_R                                       $8      !0, ->69
          2    > > FE_FETCH_R                                               $8, !1, ->69
   16     3    >   NEW                                              $9      'DateTime'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $9
   17     7        INIT_METHOD_CALL                                         !2, 'format'
          8        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
          9        DO_FCALL                                      0  $12     
         10        ASSIGN                                                   !3, $12
   18    11        CLONE                                            ~14     !2
         12        INIT_METHOD_CALL                                         ~14, 'modify'
         13        SEND_VAL_EX                                              '%2B1+day'
         14        DO_FCALL                                      0  $15     
         15        INIT_METHOD_CALL                                         $15, 'format'
         16        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         17        DO_FCALL                                      0  $16     
         18        ASSIGN                                                   !4, $16
   19    19        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !5, !3
         20        BOOL_NOT                                         ~19     ~18
         21      > JMPZ                                                     ~19, ->32
   20    22    >   INIT_METHOD_CALL                                         !2, 'format'
         23        SEND_VAL_EX                                              'jS+M+ga'
         24        DO_FCALL                                      0  $21     
         25        ASSIGN_DIM                                               !5, !4
         26        OP_DATA                                                  $21
   21    27        FETCH_DIM_W                                      $23     !5, !4
         28        MAKE_REF                                         $24     $23
         29        FETCH_DIM_W                                      $22     !6
         30        ASSIGN_REF                                               $22, $24
   22    31      > JMP                                                      ->2
   25    32    >   INIT_FCALL                                               'str_contains'
         33        FETCH_DIM_R                                      ~26     !5, !3
         34        SEND_VAL                                                 ~26
         35        INIT_METHOD_CALL                                         !2, 'format'
         36        SEND_VAL_EX                                              'M'
         37        DO_FCALL                                      0  $27     
         38        SEND_VAR                                                 $27
         39        DO_ICALL                                         $28     
         40      > JMPZ                                                     $28, ->53
   27    41    >   INIT_FCALL                                               'preg_replace'
   28    42        SEND_VAL                                                 '%2F%5Btdh%5D%5Cb%5CK%5B%5E+%5D%2A%2F'
   29    43        INIT_METHOD_CALL                                         !2, 'format'
         44        SEND_VAL_EX                                              '-jS'
         45        DO_FCALL                                      0  $30     
         46        SEND_VAR                                                 $30
   30    47        FETCH_DIM_R                                      ~31     !5, !3
         48        SEND_VAL                                                 ~31
   27    49        DO_ICALL                                         $32     
         50        ASSIGN_DIM                                               !5, !3
   30    51        OP_DATA                                                  $32
   25    52      > JMP                                                      ->64
   34    53    >   INIT_FCALL                                               'preg_replace'
   35    54        SEND_VAL                                                 '%2F+%28%3F%3D%5B%5E+%5D%2A%24%29%2F'
   36    55        INIT_METHOD_CALL                                         !2, 'format'
         56        SEND_VAL_EX                                              '+-+jS+M+'
         57        DO_FCALL                                      0  $34     
         58        SEND_VAR                                                 $34
   37    59        FETCH_DIM_R                                      ~35     !5, !3
         60        SEND_VAL                                                 ~35
   34    61        DO_ICALL                                         $36     
         62        ASSIGN_DIM                                               !5, !3
   37    63        OP_DATA                                                  $36
   40    64    >   FETCH_DIM_W                                      $38     !5, !3
         65        MAKE_REF                                         $39     $38
         66        FETCH_DIM_W                                      $37     !5, !4
         67        ASSIGN_REF                                               $37, $39
   15    68      > JMP                                                      ->2
         69    >   FE_FREE                                                  $8
   42    70        INIT_FCALL                                               'implode'
         71        SEND_VAL                                                 '%2C+'
         72        SEND_VAR                                                 !6
         73        DO_ICALL                                         $41     
         74        ECHO                                                     $41
         75      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.65 ms | 1007 KiB | 16 Q