3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getLineChartPromedio($format = 'Y-m-d'){ $startDate = '2020-07-08'; //$this->input->post('startDate'); $endDate = '2020-07-12'; //$this->input->post('endDate'); // Declare an empty array $arraydias = array(); // Variable that store the date interval // of period 1 day $interval = new DateInterval('P1D'); $realEnd = new DateTime($endDate); $realEnd->add($interval); $period = new DatePeriod(new DateTime($startDate), $interval, $realEnd); // Use loop to store date into array foreach($period as $date) { $fecha = $date->format($format); $arraydias[] = $fecha; } $string = "'" . implode("','", $arraydias) . "'"; echo json_encode($string); } getLineChartPromedio();
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
"'2020-07-08','2020-07-09','2020-07-10','2020-07-11','2020-07-12'"

preferences:
90.24 ms | 406 KiB | 5 Q