3v4l.org

run code in 300+ PHP versions simultaneously
<?php function work_days_between_two_dates(\DateTime $begin, \DateTime $end) { $workdays = []; $all_days = new DatePeriod($begin, new DateInterval('P1D'), $end->modify('+1 day')); foreach ($all_days as $day) { $dow = (int)$day->format('w'); $dom = (int)$day->format('j'); if (1 <= $dow && $dow <= 5) { // Mon - Fri $workdays[] = $day; } else if (6 == $dow && 0 == $dom % 2) { // Even Saturday $workdays[] = $day; } } return $workdays; } $begin = new \DateTime('2015-11-01'); $end = new \DateTime('2015-11-14'); $days = work_days_between_two_dates($begin, $end); foreach ($days as $day) { echo $day->format('Y-m-d') . PHP_EOL; }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.31, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
2015-11-02 2015-11-03 2015-11-04 2015-11-05 2015-11-06 2015-11-09 2015-11-10 2015-11-11 2015-11-12 2015-11-13 2015-11-14
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/vrhsa on line 4
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: syntax error, unexpected '[' in /in/vrhsa on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: parse error, unexpected '[' in /in/vrhsa on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/vrhsa on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/vrhsa on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: parse error, expecting `')'' in /in/vrhsa on line 3
Process exited with code 255.

preferences:
87.87 ms | 414 KiB | 5 Q