3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dbRows = [ ['day' => '2018-04-09', 'count' => 3], ['day' => '2018-04-08', 'count' => 6], ['day' => '2018-04-07', 'count' => 2], ['day' => '2018-04-05', 'count' => 4], ]; $interval = new \DateInterval('P10D'); $currentDate = new \DateTime; $previousDate = clone $currentDate; $previousDate->sub($interval); /* $query = 'SELECT Date( timestamp ) AS day, Count(id) AS total FROM goals_data WHERE company = 1 AND Date( timestamp ) BETWEEN :previous_date AND :current_date GROUP BY day desc' */ $dbDates = array_column($dbRows, null, 'day'); $period = new \DatePeriod($currentDate, DateInterval::createFromDateString('-1 day'), $interval->d); foreach ($period as $date) { $key = $date->format('Y-m-d'); if (!array_key_exists($key, $dbDates)) { $dbDates[$key] = ['day' => $key, 'count' => 0]; } echo $dbDates[$key]['day'] . ' ----- ' . $dbDates[$key]['count'] . \PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
2018-04-11 ----- 0 2018-04-10 ----- 0 2018-04-09 ----- 3 2018-04-08 ----- 6 2018-04-07 ----- 2 2018-04-06 ----- 0 2018-04-05 ----- 4 2018-04-04 ----- 0 2018-04-03 ----- 0 2018-04-02 ----- 0 2018-04-01 ----- 0

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:
98.53 ms | 406 KiB | 5 Q