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);

preferences:
59.7 ms | 2067 KiB | 5 Q