I'm trying to get an array of all dates between the 2 dates which im getting out the database for each row. for example there is 3 rows with 2017-02-02 and 2017-02-03 and a row with 2017-02-18 and 2017-02-20 I would like to get an array with the output [2017-02-02, 2017-02-03, 2017-02-18, 2017-02-19, 2017-02-20]
So far I have a query which gets all of the dates and echo's the start and end date and a script to get an array with the dates between 2 dates.
How can I make it work so it's getting all the dates of every row into one array?
<?php
$result = mysqli_query($con, "SELECT * FROM invoice_line WHERE car_car_id = $id");
while ($auto = mysqli_fetch_array($result)) {
?>
<h2 class="title_car">
<?php echo $auto['start_date'] . ' - ' . $auto['end_date'];?>
</h2>
<hr>
<?php $dateRange = getDateRange($auto['start_date'], $auto['end_date']); ?>
<?php } ?>
<?php
function getDateRange($startDate, $endDate, $format="Y-m-d")
{
//Create output variable
$datesArray = array();
//Calculate number of days in the range
$total_days = round(abs(strtotime($endDate) - strtotime($startDate)) / 86400, 0) + 1;
//Populate array of weekdays and counts
for($day=0; $day<$total_days; $day++)
{
$datesArray[] = date($format, strtotime("{$startDate} + {$day} days"));
}
//Return results array
return $datesArray;
}
print_r($dateRange);
?>