3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_date = '2014-01-01'; $end_date = '2015-01-31'; $date_regex = "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/"; if (!empty($start_date) & !empty($end_date) && preg_match($date_regex, $start_date) && preg_match($date_regex, $end_date)) { $start = new \DateTime($start_date); $end = new \DateTime($end_date); $intervals = []; while ($start <= $end) { $intervals[ $start->format('Y-m-d') ] = date('Y-m-t', strtotime($start->format('Y-m'))); $start->modify('first day of next month'); } echo '<pre>';print_r($intervals); }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
<pre>Array ( [2014-01-01] => 2014-01-31 [2014-02-01] => 2014-02-28 [2014-03-01] => 2014-03-31 [2014-04-01] => 2014-04-30 [2014-05-01] => 2014-05-31 [2014-06-01] => 2014-06-30 [2014-07-01] => 2014-07-31 [2014-08-01] => 2014-08-31 [2014-09-01] => 2014-09-30 [2014-10-01] => 2014-10-31 [2014-11-01] => 2014-11-30 [2014-12-01] => 2014-12-31 [2015-01-01] => 2015-01-31 )
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/drDhf on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/drDhf on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/drDhf on line 10 Parse error: syntax error, unexpected '[' in /in/drDhf on line 12
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, 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/drDhf on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/drDhf on line 10 Parse error: parse error, unexpected '[' in /in/drDhf on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/drDhf on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/drDhf on line 10 Parse error: parse error in /in/drDhf on line 12
Process exited with code 255.

preferences:
299.36 ms | 402 KiB | 458 Q