3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ "08:30", "09:00", "09:30", "10:00", "14:30", "15:00", "15:30", "16:00", "16:30" ], [ "13:30", "14:00", "14:30", "18:00", "18:30", "19:00" ] ]; function compactTimes( array $times, string $format = 'H:i', string $separation = "30 minutes" ): array { $result = []; $prev = null; foreach ($times as $time) { if (!$prev || $time !== date("H:i", strtotime("+$separation $prev"))) { unset($ref); $ref = [$time, $time]; $result[] =& $ref; } else { $ref[1] = $time; } $prev = $time; } return $result; } var_export( array_map('compactTimes', $array) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aLasP
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   45     1        INIT_FCALL                                               'var_export'
   46     2        INIT_FCALL                                               'array_map'
          3        SEND_VAL                                                 'compactTimes'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
   45     7        DO_ICALL                                                 
   47     8      > RETURN                                                   1

Function compacttimes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 34
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 22
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/aLasP
function name:  compactTimes
number of ops:  39
compiled vars:  !0 = $times, !1 = $format, !2 = $separation, !3 = $result, !4 = $prev, !5 = $time, !6 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'H%3Ai'
          2        RECV_INIT                                        !2      '30+minutes'
   30     3        ASSIGN                                                   !3, <array>
   31     4        ASSIGN                                                   !4, null
   32     5      > FE_RESET_R                                       $9      !0, ->34
          6    > > FE_FETCH_R                                               $9, !5, ->34
   33     7    >   BOOL_NOT                                         ~10     !4
          8      > JMPNZ_EX                                         ~10     ~10, ->22
          9    >   INIT_FCALL                                               'date'
         10        SEND_VAL                                                 'H%3Ai'
         11        INIT_FCALL                                               'strtotime'
         12        ROPE_INIT                                     4  ~12     '%2B'
         13        ROPE_ADD                                      1  ~12     ~12, !2
         14        ROPE_ADD                                      2  ~12     ~12, '+'
         15        ROPE_END                                      3  ~11     ~12, !4
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $14     
         18        SEND_VAR                                                 $14
         19        DO_ICALL                                         $15     
         20        IS_NOT_IDENTICAL                                 ~16     !5, $15
         21        BOOL                                             ~10     ~16
         22    > > JMPZ                                                     ~10, ->30
   34    23    >   UNSET_CV                                                 !6
   35    24        INIT_ARRAY                                       ~17     !5
         25        ADD_ARRAY_ELEMENT                                ~17     !5
         26        ASSIGN                                                   !6, ~17
   36    27        FETCH_DIM_W                                      $19     !3
         28        ASSIGN_REF                                               $19, !6
   33    29      > JMP                                                      ->32
   38    30    >   ASSIGN_DIM                                               !6, 1
         31        OP_DATA                                                  !5
   40    32    >   ASSIGN                                                   !4, !5
   32    33      > JMP                                                      ->6
         34    >   FE_FREE                                                  $9
   42    35        VERIFY_RETURN_TYPE                                       !3
         36      > RETURN                                                   !3
   43    37*       VERIFY_RETURN_TYPE                                       
         38*     > RETURN                                                   null

End of function compacttimes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.12 ms | 1018 KiB | 17 Q