3v4l.org

run code in 300+ PHP versions simultaneously
<?php $objToday = new Datetime(); $objFirstOfMonth = new DateTime('first day of this month'); $intNumberOfWorkDays = 0; $obj1Day = new DateInterval('P1D'); while ($objToday >= $objFirstOfMonth && $intNumberOfWorkDays <= 5) { if ($objFirstOfMonth->format('N') < 6) { $intNumberOfWorkDays++; } echo sprintf('%s:%s', $intNumberOfWorkDays, $objFirstOfMonth->format('N d.m.Y')) . "\r\n"; $objFirstOfMonth = $objFirstOfMonth->add($obj1Day); } if ($intNumberOfWorkDays == 5) { echo 'Boooyaaah!'; } else { echo $intNumberOfWorkDays; }
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
0:7 01.11.2015 1:1 02.11.2015 2:2 03.11.2015 3:3 04.11.2015 3
Output for 5.6.28, 7.0.20
0:7 01.11.2015 1:1 02.11.2015 2:2 03.11.2015 3:3 04.11.2015 4:4 05.11.2015 4
Output for 7.0.6
0:7 01.05.2016 1:1 02.05.2016 2:2 03.05.2016 2
Output for 7.0.5
1:5 01.04.2016 1:6 02.04.2016 1:7 03.04.2016 1
Output for 5.5.31 - 5.5.33, 5.6.15 - 5.6.19, 7.0.0 - 7.0.4
1:2 01.03.2016 2:3 02.03.2016 3:4 03.03.2016 4:5 04.03.2016 4:6 05.03.2016 4:7 06.03.2016 5:1 07.03.2016 6:2 08.03.2016 6
Output for 5.6.21
0:7 01.05.2016 1:1 02.05.2016 1
Output for 5.5.25 - 5.5.29, 5.5.34, 5.6.8 - 5.6.13, 5.6.20
1:5 01.04.2016 1:6 02.04.2016 1:7 03.04.2016 2:1 04.04.2016 3:2 05.04.2016 4:3 06.04.2016 5:4 07.04.2016 6:5 08.04.2016 6
Output for 5.6.14
1:5 01.04.2016 1:6 02.04.2016 1
Output for 5.5.24, 5.5.35
0:7 01.05.2016 1:1 02.05.2016 2:2 03.05.2016 3:3 04.05.2016 4:4 05.05.2016 5:5 06.05.2016 5:6 07.05.2016 5:7 08.05.2016 6:1 09.05.2016 6
Output for 5.5.30
1:5 01.04.2016 1

preferences:
148.01 ms | 401 KiB | 183 Q