3v4l.org

run code in 300+ PHP versions simultaneously
<?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'));
Output for git.master, git.master_jit, rfc.property-hooks
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" }

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:
64 ms | 401 KiB | 8 Q