3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * @param string $start * @param string $end * * @return string[] */ function date_period_grid($start, $end) { $start = new DateTime($start); $end = new DateTime($end); $i = $end->diff($start); $days = $i->days; $months = $i->y * 12 + $i->m + ($i->d ? 1 : 0); $years = $i->y + (($i->m || $i->d) ? 1 : 0); if ($years > 1) { $period = new DatePeriod($start, new DateInterval('P1Y'), $years); } elseif ($months > 1) { $period = new DatePeriod($start, new DateInterval('P1M'), $months); } else { $period = new DatePeriod($start, new DateInterval('P1D'), $days); } $result = []; foreach ($period as $date) { $result[] = $date->format('Y-m-d'); } return $result; } var_dump(date_period_grid('2012-07-01', '2015-11-01'));
based on FjJ4O
Output for 5.4.0 - 7.3.0rc4
array(5) { [0]=> string(10) "2012-07-01" [1]=> string(10) "2013-07-01" [2]=> string(10) "2014-07-01" [3]=> string(10) "2015-07-01" [4]=> string(10) "2016-07-01" }
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/CQlI1 on line 28
Process exited with code 255.