3v4l.org

run code in 300+ PHP versions simultaneously
<?php $openTimeslots = [ '02-09-2021' => [ '8:00-10:00', '16:00-19:00' ], '03-09-2021' => [ '7:00-10:00', '16:15-19:00', '14:00-16:00', '13:00-14:15' ], '04-09-2021' => [ '7:15-10:00', '15:15-18:15' ], '05-09-2021' => [ '8:15-8:45', '9:15-9:45', '16:15-19:00', ] ]; function slotToInts($slot) { return sscanf(str_replace(':', '', $slot), "%d-%d"); } $commons = array_map('slotToInts', array_shift($openTimeslots)); foreach ($openTimeslots as $slots) { $newCommons = []; foreach ($slots as $slot) { [$start, $end] = slotToInts($slot); foreach ($commons as [$commonStart, $commonEnd]) { $newCommonStart = null; $newCommonEnd = null; if ($start >= $commonStart && $start < $commonEnd) { $newCommonStart = $start; } if ($end > $commonStart && $end <= $commonEnd) { $newCommonEnd = $end; } if ($newCommonStart || $newCommonEnd) { $newCommons[] = [ $newCommonStart ?? $commonStart, $newCommonEnd ?? $commonEnd ]; } } } $commons = $newCommons; } var_export( array_map( fn($subarray) => implode('-', preg_replace('~(?=\d{2}(?:-|$))~', ':', $subarray)), $commons ) );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 60
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 60
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 57
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 57
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 55
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 55
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 37
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 43
Branch analysis from position: 42
2 jumps found. (Code = 47) Position 1 = 44, Position 2 = 45
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 54
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 54
Branch analysis from position: 45
Branch analysis from position: 43
Branch analysis from position: 41
Branch analysis from position: 37
Branch analysis from position: 35
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 55
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 57
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
filename:       /in/v24DG
function name:  (null)
number of ops:  70
compiled vars:  !0 = $openTimeslots, !1 = $commons, !2 = $slots, !3 = $newCommons, !4 = $slot, !5 = $start, !6 = $end, !7 = $commonStart, !8 = $commonEnd, !9 = $newCommonStart, !10 = $newCommonEnd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'slotToInts'
          3        INIT_FCALL                                               'array_shift'
          4        SEND_REF                                                 !0
          5        DO_ICALL                                         $12     
          6        SEND_VAR                                                 $12
          7        DO_ICALL                                         $13     
          8        ASSIGN                                                   !1, $13
   31     9      > FE_RESET_R                                       $15     !0, ->60
         10    > > FE_FETCH_R                                               $15, !2, ->60
   32    11    >   ASSIGN                                                   !3, <array>
   33    12      > FE_RESET_R                                       $17     !2, ->57
         13    > > FE_FETCH_R                                               $17, !4, ->57
   34    14    >   INIT_FCALL                                               'slottoints'
         15        SEND_VAR                                                 !4
         16        DO_FCALL                                      0  $18     
         17        FETCH_LIST_R                                     $19     $18, 0
         18        ASSIGN                                                   !5, $19
         19        FETCH_LIST_R                                     $21     $18, 1
         20        ASSIGN                                                   !6, $21
         21        FREE                                                     $18
   35    22      > FE_RESET_R                                       $23     !1, ->55
         23    > > FE_FETCH_R                                               $23, $24, ->55
         24    >   FETCH_LIST_R                                     $25     $24, 0
         25        ASSIGN                                                   !7, $25
         26        FETCH_LIST_R                                     $27     $24, 1
         27        ASSIGN                                                   !8, $27
         28        FREE                                                     $24
   36    29        ASSIGN                                                   !9, null
   37    30        ASSIGN                                                   !10, null
   38    31        IS_SMALLER_OR_EQUAL                              ~31     !7, !5
         32      > JMPZ_EX                                          ~31     ~31, ->35
         33    >   IS_SMALLER                                       ~32     !5, !8
         34        BOOL                                             ~31     ~32
         35    > > JMPZ                                                     ~31, ->37
   39    36    >   ASSIGN                                                   !9, !5
   41    37    >   IS_SMALLER                                       ~34     !7, !6
         38      > JMPZ_EX                                          ~34     ~34, ->41
         39    >   IS_SMALLER_OR_EQUAL                              ~35     !6, !8
         40        BOOL                                             ~34     ~35
         41    > > JMPZ                                                     ~34, ->43
   42    42    >   ASSIGN                                                   !10, !6
   44    43    > > JMPNZ_EX                                         ~37     !9, ->45
         44    >   BOOL                                             ~37     !10
         45    > > JMPZ                                                     ~37, ->54
   46    46    >   COALESCE                                         ~39     !9
         47        QM_ASSIGN                                        ~39     !7
         48        INIT_ARRAY                                       ~40     ~39
   47    49        COALESCE                                         ~41     !10
         50        QM_ASSIGN                                        ~41     !8
         51        ADD_ARRAY_ELEMENT                                ~40     ~41
   45    52        ASSIGN_DIM                                               !3
   47    53        OP_DATA                                                  ~40
   35    54    > > JMP                                                      ->23
         55    >   FE_FREE                                                  $23
   33    56      > JMP                                                      ->13
         57    >   FE_FREE                                                  $17
   52    58        ASSIGN                                                   !1, !3
   31    59      > JMP                                                      ->10
         60    >   FE_FREE                                                  $15
   54    61        INIT_FCALL                                               'var_export'
   55    62        INIT_FCALL                                               'array_map'
   56    63        DECLARE_LAMBDA_FUNCTION                          ~43     [0]
         64        SEND_VAL                                                 ~43
   57    65        SEND_VAR                                                 !1
   55    66        DO_ICALL                                         $44     
   57    67        SEND_VAR                                                 $44
   54    68        DO_ICALL                                                 
   59    69      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v24DG
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $subarray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '-'
          3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAL                                                 '%7E%28%3F%3D%5Cd%7B2%7D%28%3F%3A-%7C%24%29%29%7E'
          5        SEND_VAL                                                 '%3A'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $1      
          8        SEND_VAR                                                 $1
          9        DO_ICALL                                         $2      
         10      > RETURN                                                   $2
         11*     > RETURN                                                   null

End of Dynamic Function 0

Function slottoints:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v24DG
function name:  slotToInts
number of ops:  12
compiled vars:  !0 = $slot
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'sscanf'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '%3A'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        SEND_VAL                                                 '%25d-%25d'
          9        DO_ICALL                                         $2      
         10      > RETURN                                                   $2
   27    11*     > RETURN                                                   null

End of function slottoints

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.08 ms | 1018 KiB | 21 Q