3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ [ 'time' => '00:00:00', 'sales' => 55.99, 'orders' => 1, ], [ 'time' => '06:00:00', 'sales' => 46.37, 'orders' => 1, ], [ 'time' => '08:00:00', 'sales' => 246.56, 'orders' => 4, ], [ 'time' => '10:00:00', 'sales' => 78.66, 'orders' => 1, ] ]; // isolate the times $times = array_map(function ($row) { return $row['time']; }, $rows); // create a list of similarly formatted times from 00:00:00 - 22:00:00 $allTimes = array_map(function ($hour) { return sprintf('%02d:00:00', $hour); }, range(0, 22, 2)); // compute the difference $notTimes = array_diff($allTimes, $times); // add the notTimes to the original rowset with default values foreach ($notTimes as $notTime) { $rows[] = [ 'time' => $notTime, 'sales' => 0, 'orders' => 0, ]; } var_dump($rows);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/OJgbO
function name:  (null)
number of ops:  36
compiled vars:  !0 = $rows, !1 = $times, !2 = $allTimes, !3 = $notTimes, !4 = $notTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   27     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOJgbO%3A27%240'
   29     3        SEND_VAL                                                 ~6
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
   27     6        ASSIGN                                                   !1, $7
   32     7        INIT_FCALL                                               'array_map'
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOJgbO%3A32%241'
   34     9        SEND_VAL                                                 ~9
         10        INIT_FCALL                                               'range'
         11        SEND_VAL                                                 0
         12        SEND_VAL                                                 22
         13        SEND_VAL                                                 2
         14        DO_ICALL                                         $10     
         15        SEND_VAR                                                 $10
         16        DO_ICALL                                         $11     
   32    17        ASSIGN                                                   !2, $11
   37    18        INIT_FCALL                                               'array_diff'
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $13     
         22        ASSIGN                                                   !3, $13
   40    23      > FE_RESET_R                                       $15     !3, ->31
         24    > > FE_FETCH_R                                               $15, !4, ->31
   43    25    >   INIT_ARRAY                                       ~17     !4, 'time'
   44    26        ADD_ARRAY_ELEMENT                                ~17     0, 'sales'
   45    27        ADD_ARRAY_ELEMENT                                ~17     0, 'orders'
   42    28        ASSIGN_DIM                                               !0
   45    29        OP_DATA                                                  ~17
   40    30      > JMP                                                      ->24
         31    >   FE_FREE                                                  $15
   49    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FOJgbO%3A27%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OJgbO
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        FETCH_DIM_R                                      ~1      !0, 'time'
          2      > RETURN                                                   ~1
   29     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOJgbO%3A27%240

Function %00%7Bclosure%7D%2Fin%2FOJgbO%3A32%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OJgbO
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $hour
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%2502d%3A00%3A00'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   34     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOJgbO%3A32%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.6 ms | 1400 KiB | 23 Q