3v4l.org

run code in 300+ PHP versions simultaneously
<?php \date_default_timezone_set('UTC'); $dates = ['2019-01-18', '2019-01-01', '2018-12-01', '2018-12-20', null]; $today = new \DateTimeImmutable('2019-01-01'); $yesterday = $today->modify('-1 day'); $results = []; foreach ($dates as $iDate) { $_GET['importDate'] = $iDate; $results[$iDate] = ''; if (!$start = \date_create(!empty($_GET['importDate']) ? $_GET['importDate'] : $yesterday->format('Y-m-d'))) { die('Invalid Date Supplied'); } if ($start > $today) { $results[$iDate] .= 'Dates set in the future are not permitted' . \PHP_EOL; continue; } //start at the first day of the month $start->modify('first day of this month')->setTime(0,0,0); //validate the current month to prevent future dates if ($start->format('Y-m') === $today->format('Y-m')) { $end = \date_create($yesterday->format('Y-m-d'))->setTime(23,59,59); if ($end < $start) { //yesterday was last month $end = clone $start; } } else { $end = clone $start; $end->modify('last day of this month'); } //end at midnight $end->setTime(23,59,59); $importDates = new \DatePeriod($start, new \DateInterval('P1D'), $end); foreach ($importDates as $date) { $dateImport = $date->format('Y-m-d'); $results[$iDate] .= $dateImport . \PHP_EOL; //... } } //display the results $values = array_reduce(\array_keys($results), function($carry, $item) use ($results) { if (!in_array($results[$item], $carry)) { $carry[] = $results[$item]; } return $carry; }, []); echo 'Current Date: ' . $today->format('Y-m-d') . \PHP_EOL . \PHP_EOL; foreach ($values as $info) { $dates = '"' . implode('", "', array_keys($results, $info)) . '"'; echo <<<EOL Import Dates: $dates $info EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
Current Date: 2019-01-01 Import Dates: "2019-01-18" Dates set in the future are not permitted Import Dates: "2019-01-01" 2019-01-01 Import Dates: "2018-12-01", "2018-12-20", "" 2018-12-01 2018-12-02 2018-12-03 2018-12-04 2018-12-05 2018-12-06 2018-12-07 2018-12-08 2018-12-09 2018-12-10 2018-12-11 2018-12-12 2018-12-13 2018-12-14 2018-12-15 2018-12-16 2018-12-17 2018-12-18 2018-12-19 2018-12-20 2018-12-21 2018-12-22 2018-12-23 2018-12-24 2018-12-25 2018-12-26 2018-12-27 2018-12-28 2018-12-29 2018-12-30 2018-12-31

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:
136.19 ms | 407 KiB | 5 Q