3v4l.org

run code in 500+ PHP versions simultaneously
<?php $resultSet = [ 0 => [ 'id' => 123, 'name' => 'ABC', 'start_date' => '2019-12-18 20:00:00' ], 1 => [ 'id' => 124, 'name' => 'CDE', 'start_date' => '2019-12-19 20:00:00' ], 2 => [ 'id' => 125, 'name' => 'TEST', 'start_date' => '2019-12-23 20:00:00' ], 3 => [ 'id' => 126, 'name' => 'BWM', 'start_date' => '2019-12-18 20:00:00' ], 4 => [ 'id' => 127, 'name' => 'XYZ', 'start_date' => '2019-12-19 20:00:00' ], 5 => [ 'id' => 128, 'name' => 'GHJ', 'start_date' => '2019-12-21 20:00:00' ], 6 => [ 'id' => 129, 'name' => 'GHJK', 'start_date' => '2019-12-22 20:00:00' ], 7 => [ 'id' => 130, 'name' => 'GHL', 'start_date' => '2019-12-20 20:00:00' ], 8 => [ 'id' => 131, 'name' => 'JKL', 'start_date' => '2019-12-25 20:00:00' ] ]; $s = new DateTime(); $s->modify('+2 days'); // in fact today is 2019-12-16, but you've choose 2019-12-18 //echo $s->format('Y-m-d H:i:s').PHP_EOL; // today $today = $s->format('Ymd'); // format 20191218 echo $today.' <- today'.PHP_EOL; // today $nextmonday = $s->modify('next monday')->format('Ymd'); echo $nextmonday.' <- next monday'.PHP_EOL.PHP_EOL; // next monday, format 20191223 foreach($resultSet as $rec){ $d = date('Ymd', strtotime($rec['start_date'])); $d2 = date('l', strtotime($rec['start_date'])); echo $d.' --- '.$d2.PHP_EOL; if ($d == $today) { // 2019-12-18 == 2019-12-18 $res['today'][] = $rec; } else if ($d - $today == 1) { // 2019-12-19 - 2019-12-18 == 1 $res['tomorrow'][] = $rec; } else if (in_array($d2,['Friday','Saturday','Sunday']) && $d < $nextmonday){ // < 2019-12-23 and by day name $res['this_weekend'][] = $rec; } else if ($d >= $nextmonday){ // next week (not a weekend) $res['next_weekend'][] = $rec; } } echo PHP_EOL; print_r($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 77
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 77
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 62
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 62
2 jumps found. (Code = 46) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 71
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 76
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 76
Branch analysis from position: 66
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
filename:       /in/GdvjD
function name:  (null)
number of ops:  83
compiled vars:  !0 = $resultSet, !1 = $s, !2 = $today, !3 = $nextmonday, !4 = $rec, !5 = $d, !6 = $d2, !7 = $res
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   50     1        NEW                                                  $9      'DateTime'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $9
   51     4        INIT_METHOD_CALL                                             !1, 'modify'
          5        SEND_VAL_EX                                                  '%2B2+days'
          6        DO_FCALL                                          0          
   53     7        INIT_METHOD_CALL                                             !1, 'format'
          8        SEND_VAL_EX                                                  'Ymd'
          9        DO_FCALL                                          0  $13     
         10        ASSIGN                                                       !2, $13
   55    11        CONCAT                                               ~15     !2, '+%3C-+today'
         12        CONCAT                                               ~16     ~15, '%0A'
         13        ECHO                                                         ~16
   57    14        INIT_METHOD_CALL                                             !1, 'modify'
         15        SEND_VAL_EX                                                  'next+monday'
         16        DO_FCALL                                          0  $17     
         17        INIT_METHOD_CALL                                             $17, 'format'
         18        SEND_VAL_EX                                                  'Ymd'
         19        DO_FCALL                                          0  $18     
         20        ASSIGN                                                       !3, $18
   58    21        CONCAT                                               ~20     !3, '+%3C-+next+monday'
         22        CONCAT                                               ~21     ~20, '%0A'
         23        CONCAT                                               ~22     ~21, '%0A'
         24        ECHO                                                         ~22
   61    25      > FE_RESET_R                                           $23     !0, ->77
         26    > > FE_FETCH_R                                                   $23, !4, ->77
   62    27    >   INIT_FCALL                                                   'date'
         28        SEND_VAL                                                     'Ymd'
         29        INIT_FCALL                                                   'strtotime'
         30        FETCH_DIM_R                                          ~24     !4, 'start_date'
         31        SEND_VAL                                                     ~24
         32        DO_ICALL                                             $25     
         33        SEND_VAR                                                     $25
         34        DO_ICALL                                             $26     
         35        ASSIGN                                                       !5, $26
   63    36        INIT_FCALL                                                   'date'
         37        SEND_VAL                                                     'l'
         38        INIT_FCALL                                                   'strtotime'
         39        FETCH_DIM_R                                          ~28     !4, 'start_date'
         40        SEND_VAL                                                     ~28
         41        DO_ICALL                                             $29     
         42        SEND_VAR                                                     $29
         43        DO_ICALL                                             $30     
         44        ASSIGN                                                       !6, $30
   64    45        CONCAT                                               ~32     !5, '+---+'
         46        CONCAT                                               ~33     ~32, !6
         47        CONCAT                                               ~34     ~33, '%0A'
         48        ECHO                                                         ~34
   66    49        IS_EQUAL                                                     !5, !2
         50      > JMPZ                                                         ~35, ->55
   67    51    >   FETCH_DIM_W                                          $36     !7, 'today'
         52        ASSIGN_DIM                                                   $36
         53        OP_DATA                                                      !4
   66    54      > JMP                                                          ->76
   68    55    >   SUB                                                  ~38     !5, !2
         56        IS_EQUAL                                                     ~38, 1
         57      > JMPZ                                                         ~39, ->62
   69    58    >   FETCH_DIM_W                                          $40     !7, 'tomorrow'
         59        ASSIGN_DIM                                                   $40
         60        OP_DATA                                                      !4
   68    61      > JMP                                                          ->76
   70    62    >   IN_ARRAY                                             ~42     !6, <array>
         63      > JMPZ_EX                                              ~42     ~42, ->66
         64    >   IS_SMALLER                                           ~43     !5, !3
         65        BOOL                                                 ~42     ~43
         66    > > JMPZ                                                         ~42, ->71
   71    67    >   FETCH_DIM_W                                          $44     !7, 'this_weekend'
         68        ASSIGN_DIM                                                   $44
         69        OP_DATA                                                      !4
   70    70      > JMP                                                          ->76
   72    71    >   IS_SMALLER_OR_EQUAL                                          !3, !5
         72      > JMPZ                                                         ~46, ->76
   73    73    >   FETCH_DIM_W                                          $47     !7, 'next_weekend'
         74        ASSIGN_DIM                                                   $47
         75        OP_DATA                                                      !4
   61    76    > > JMP                                                          ->26
         77    >   FE_FREE                                                      $23
   76    78        ECHO                                                         '%0A'
   78    79        INIT_FCALL                                                   'print_r'
         80        SEND_VAR                                                     !7
         81        DO_ICALL                                                     
         82      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.74 ms | 2705 KiB | 16 Q