3v4l.org

run code in 500+ 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, ]; } // sort, because why not usort($rows, function ($rowOne, $rowTwo) { return ((int) $rowOne['time']) > ((int) $rowTwo['time']); }); // dump 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/RrNKA
function name:  (null)
number of ops:  41
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                              ~6      [0]
   29     3        SEND_VAL                                                     ~6
          4        SEND_VAR                                                     !0
   27     5        DO_ICALL                                             $7      
          6        ASSIGN                                                       !1, $7
   32     7        INIT_FCALL                                                   'array_map'
          8        DECLARE_LAMBDA_FUNCTION                              ~9      [1]
   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
   32    16        DO_ICALL                                             $11     
         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
   50    32        INIT_FCALL                                                   'usort'
         33        SEND_REF                                                     !0
         34        DECLARE_LAMBDA_FUNCTION                              ~18     [2]
   52    35        SEND_VAL                                                     ~18
   50    36        DO_ICALL                                                     
   55    37        INIT_FCALL                                                   'var_dump'
         38        SEND_VAR                                                     !0
         39        DO_ICALL                                                     
         40      > 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/RrNKA
function name:  {closure:/in/RrNKA:27}
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 Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RrNKA
function name:  {closure:/in/RrNKA:32}
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 Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RrNKA
function name:  {closure:/in/RrNKA:50}
number of ops:  9
compiled vars:  !0 = $rowOne, !1 = $rowTwo
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   51     2        FETCH_DIM_R                                          ~2      !0, 'time'
          3        CAST                                              4  ~3      ~2
          4        FETCH_DIM_R                                          ~4      !1, 'time'
          5        CAST                                              4  ~5      ~4
          6        IS_SMALLER                                           ~6      ~5, ~3
          7      > RETURN                                                       ~6
   52     8*     > RETURN                                                       null

End of Dynamic Function 2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
181.22 ms | 3205 KiB | 18 Q