3v4l.org

run code in 300+ PHP versions simultaneously
<?php $reserved_dates = array( '2023-12-03', '2023-12-10', '2023-12-17', '2023-12-24', '2023-12-31', '2024-01-07', '2024-01-14', '2024-01-21', '2024-01-28', '2024-02-04', '2024-02-11', '2024-02-18', '2024-02-25', '2024-12-01', '2023-12-03', '2024-12-08', '2024-12-15', ); $data = []; foreach($reserved_dates as $d){ list($year, $month) = explode("-", $d); $data[ $year ]['year'] = $year; $data[ $year ]['months'][ $month ] = $data[ $year ]['months'][ $month ] ?? []; $data[ $year ]['months'][ $month ]['monthName'] = date("F", strtotime($d)); $data[ $year ]['months'][ $month ]['paid'] = true; // or false whatever $data[ $year ]['months'][ $month ]['dates'] = $data[ $year ]['months'][ $month ]['dates'] ?? []; $data[ $year ]['months'][ $month ]['dates'][] = $d; } foreach($data as &$months){ foreach($months['months'] as &$each_month){ usort($each_month['dates'], fn($a, $b) => DateTime::createFromFormat('!Y-m-d', $a) <=> DateTime::createFromFormat('!Y-m-d', $b)); } $months['months'] = array_values($months['months']); } $data = array_values($data); print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 60
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 60
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 60
2 jumps found. (Code = 125) Position 1 = 62, Position 2 = 81
Branch analysis from position: 62
2 jumps found. (Code = 126) Position 1 = 63, Position 2 = 81
Branch analysis from position: 63
2 jumps found. (Code = 125) Position 1 = 65, Position 2 = 73
Branch analysis from position: 65
2 jumps found. (Code = 126) Position 1 = 66, Position 2 = 73
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 73
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 81
Branch analysis from position: 60
filename:       /in/beega
function name:  (null)
number of ops:  90
compiled vars:  !0 = $reserved_dates, !1 = $data, !2 = $d, !3 = $year, !4 = $month, !5 = $months, !6 = $each_month
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, <array>
   26     2      > FE_RESET_R                                       $9      !0, ->60
          3    > > FE_FETCH_R                                               $9, !2, ->60
   27     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '-'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $10     
          8        FETCH_LIST_R                                     $11     $10, 0
          9        ASSIGN                                                   !3, $11
         10        FETCH_LIST_R                                     $13     $10, 1
         11        ASSIGN                                                   !4, $13
         12        FREE                                                     $10
   28    13        FETCH_DIM_W                                      $15     !1, !3
         14        ASSIGN_DIM                                               $15, 'year'
         15        OP_DATA                                                  !3
   29    16        FETCH_DIM_IS                                     ~20     !1, !3
         17        FETCH_DIM_IS                                     ~21     ~20, 'months'
         18        FETCH_DIM_IS                                     ~22     ~21, !4
         19        COALESCE                                         ~23     ~22
         20        QM_ASSIGN                                        ~23     <array>
         21        FETCH_DIM_W                                      $17     !1, !3
         22        FETCH_DIM_W                                      $18     $17, 'months'
         23        ASSIGN_DIM                                               $18, !4
         24        OP_DATA                                                  ~23
   30    25        INIT_FCALL                                               'date'
         26        SEND_VAL                                                 'F'
         27        INIT_FCALL                                               'strtotime'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                         $28     
         30        SEND_VAR                                                 $28
         31        DO_ICALL                                         $29     
         32        FETCH_DIM_W                                      $24     !1, !3
         33        FETCH_DIM_W                                      $25     $24, 'months'
         34        FETCH_DIM_W                                      $26     $25, !4
         35        ASSIGN_DIM                                               $26, 'monthName'
         36        OP_DATA                                                  $29
   31    37        FETCH_DIM_W                                      $30     !1, !3
         38        FETCH_DIM_W                                      $31     $30, 'months'
         39        FETCH_DIM_W                                      $32     $31, !4
         40        ASSIGN_DIM                                               $32, 'paid'
         41        OP_DATA                                                  <true>
   32    42        FETCH_DIM_IS                                     ~38     !1, !3
         43        FETCH_DIM_IS                                     ~39     ~38, 'months'
         44        FETCH_DIM_IS                                     ~40     ~39, !4
         45        FETCH_DIM_IS                                     ~41     ~40, 'dates'
         46        COALESCE                                         ~42     ~41
         47        QM_ASSIGN                                        ~42     <array>
         48        FETCH_DIM_W                                      $34     !1, !3
         49        FETCH_DIM_W                                      $35     $34, 'months'
         50        FETCH_DIM_W                                      $36     $35, !4
         51        ASSIGN_DIM                                               $36, 'dates'
         52        OP_DATA                                                  ~42
   33    53        FETCH_DIM_W                                      $43     !1, !3
         54        FETCH_DIM_W                                      $44     $43, 'months'
         55        FETCH_DIM_W                                      $45     $44, !4
         56        FETCH_DIM_W                                      $46     $45, 'dates'
         57        ASSIGN_DIM                                               $46
         58        OP_DATA                                                  !2
   26    59      > JMP                                                      ->3
         60    >   FE_FREE                                                  $9
   37    61      > FE_RESET_RW                                      $48     !1, ->81
         62    > > FE_FETCH_RW                                              $48, !5, ->81
   38    63    >   FETCH_DIM_W                                      $49     !5, 'months'
         64      > FE_RESET_RW                                      $50     $49, ->73
         65    > > FE_FETCH_RW                                              $50, !6, ->73
   39    66    >   INIT_FCALL                                               'usort'
         67        FETCH_DIM_W                                      $51     !6, 'dates'
         68        SEND_REF                                                 $51
         69        DECLARE_LAMBDA_FUNCTION                          ~52     [0]
         70        SEND_VAL                                                 ~52
         71        DO_ICALL                                                 
   38    72      > JMP                                                      ->65
         73    >   FE_FREE                                                  $50
   41    74        INIT_FCALL                                               'array_values'
         75        FETCH_DIM_R                                      ~55     !5, 'months'
         76        SEND_VAL                                                 ~55
         77        DO_ICALL                                         $56     
         78        ASSIGN_DIM                                               !5, 'months'
         79        OP_DATA                                                  $56
   37    80      > JMP                                                      ->62
         81    >   FE_FREE                                                  $48
   44    82        INIT_FCALL                                               'array_values'
         83        SEND_VAR                                                 !1
         84        DO_ICALL                                         $57     
         85        ASSIGN                                                   !1, $57
   46    86        INIT_FCALL                                               'print_r'
         87        SEND_VAR                                                 !1
         88        DO_ICALL                                                 
         89      > 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/beega
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          3        SEND_VAL                                                 '%21Y-m-d'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          7        SEND_VAL                                                 '%21Y-m-d'
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $3      
         10        SPACESHIP                                        ~4      $2, $3
         11      > RETURN                                                   ~4
         12*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.78 ms | 1451 KiB | 19 Q