3v4l.org

run code in 300+ PHP versions simultaneously
<?php $times = ['17:45', '13:12', '09:29', '17:32', '16:49', '14:18']; $counts = array_reduce($times, function($counts, $time) { $hour = (int)substr($time, 0, 2); $moment = in_array($hour, range(9, 12)) ? 'morning' : (in_array($hour, range(13, 16)) ? 'afternoon' : 'evening'); $counts[$moment]++; return $counts; }, ['morning' => 0, 'afternoon' => 0, 'evening' => 0]); echo '<pre>'; var_dump($counts); echo '</pre>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D7c9f
function name:  (null)
number of ops:  14
compiled vars:  !0 = $times, !1 = $counts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
    9     4        SEND_VAL                                                 ~3
          5        SEND_VAL                                                 <array>
    4     6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   11     8        ECHO                                                     '%3Cpre%3E'
          9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
         12        ECHO                                                     '%3C%2Fpre%3E'
         13      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D7c9f
function name:  {closure}
number of ops:  38
compiled vars:  !0 = $counts, !1 = $time, !2 = $hour, !3 = $moment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'substr'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $4      
          7        CAST                                          4  ~5      $4
          8        ASSIGN                                                   !2, ~5
    6     9        INIT_FCALL                                               'in_array'
         10        SEND_VAR                                                 !2
         11        INIT_FCALL                                               'range'
         12        SEND_VAL                                                 9
         13        SEND_VAL                                                 12
         14        DO_ICALL                                         $7      
         15        SEND_VAR                                                 $7
         16        DO_ICALL                                         $8      
         17      > JMPZ                                                     $8, ->20
         18    >   QM_ASSIGN                                        ~9      'morning'
         19      > JMP                                                      ->33
         20    >   INIT_FCALL                                               'in_array'
         21        SEND_VAR                                                 !2
         22        INIT_FCALL                                               'range'
         23        SEND_VAL                                                 13
         24        SEND_VAL                                                 16
         25        DO_ICALL                                         $10     
         26        SEND_VAR                                                 $10
         27        DO_ICALL                                         $11     
         28      > JMPZ                                                     $11, ->31
         29    >   QM_ASSIGN                                        ~12     'afternoon'
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~12     'evening'
         32    >   QM_ASSIGN                                        ~9      ~12
         33    >   ASSIGN                                                   !3, ~9
    7    34        FETCH_DIM_RW                                     $14     !0, !3
         35        PRE_INC                                                  $14
    8    36      > RETURN                                                   !0
    9    37*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.88 ms | 1009 KiB | 18 Q