3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = "2017-01-08"; $stop = "2017-01-20"; $chosenInterval = "week"; function getDates($start, $stop, $chosenInterval = "week") { $startDT = new DateTime($start); $stopDT = new DateTime($stop); if(isset($chosenInterval) && ($chosenInterval == "week" || $chosenInterval == "day") ) { $timeFormat = "F j, Y"; } else { $timeFormat = "F Y"; $chosenInterval = "month"; } $begin = (new DateTime($start))->modify('first day of this month'); $end = (new DateTime($stop))->modify('first day of next month'); $interval = DateInterval::createFromDateString('1 '.$chosenInterval); $period = new DatePeriod($begin, $interval, $end); foreach($period as $dt) { if ($chosenInterval !== "month" && ($dt < $startDT || $dt > $stopDT)) continue; $dataLabels[] = $dt->format($timeFormat); } return $dataLabels; } var_dump(getDates($start, $stop)); var_dump(getDates($start, $stop, "day")); var_dump(getDates($start, $stop, "month"));
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [0]=> string(15) "January 8, 2017" [1]=> string(16) "January 15, 2017" } array(13) { [0]=> string(15) "January 8, 2017" [1]=> string(15) "January 9, 2017" [2]=> string(16) "January 10, 2017" [3]=> string(16) "January 11, 2017" [4]=> string(16) "January 12, 2017" [5]=> string(16) "January 13, 2017" [6]=> string(16) "January 14, 2017" [7]=> string(16) "January 15, 2017" [8]=> string(16) "January 16, 2017" [9]=> string(16) "January 17, 2017" [10]=> string(16) "January 18, 2017" [11]=> string(16) "January 19, 2017" [12]=> string(16) "January 20, 2017" } array(1) { [0]=> string(12) "January 2017" }

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:
45.88 ms | 402 KiB | 8 Q