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);
Output for git.master, git.master_jit, rfc.property-hooks
20191218 <- today 20191223 <- next monday 20191218 --- Wednesday 20191219 --- Thursday 20191223 --- Monday 20191218 --- Wednesday 20191219 --- Thursday 20191221 --- Saturday 20191222 --- Sunday 20191220 --- Friday 20191225 --- Wednesday Array ( [today] => Array ( [0] => Array ( [id] => 123 [name] => ABC [start_date] => 2019-12-18 20:00:00 ) [1] => Array ( [id] => 126 [name] => BWM [start_date] => 2019-12-18 20:00:00 ) ) [tomorrow] => Array ( [0] => Array ( [id] => 124 [name] => CDE [start_date] => 2019-12-19 20:00:00 ) [1] => Array ( [id] => 127 [name] => XYZ [start_date] => 2019-12-19 20:00:00 ) ) [next_weekend] => Array ( [0] => Array ( [id] => 125 [name] => TEST [start_date] => 2019-12-23 20:00:00 ) [1] => Array ( [id] => 131 [name] => JKL [start_date] => 2019-12-25 20:00:00 ) ) [this_weekend] => Array ( [0] => Array ( [id] => 128 [name] => GHJ [start_date] => 2019-12-21 20:00:00 ) [1] => Array ( [id] => 129 [name] => GHJK [start_date] => 2019-12-22 20:00:00 ) [2] => Array ( [id] => 130 [name] => GHL [start_date] => 2019-12-20 20:00:00 ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.44 ms | 2071 KiB | 4 Q