我是一个新手,对PHP数组不太熟悉......但我已经创建了一个数组来获取在表单中提交的两个日期之间的所有日期。
请参见下面的代码:
$endDate=$_POST[todate];
$startDate =$_POST[fromdate];
print_r(getDatesFromRange( "$datef", "$dateto" ));
function getDatesFromRange($startDate, $endDate)
{
$return = array($startDate);
$start = $startDate;
$i=1;
if (strtotime($startDate) < strtotime($endDate))
{
while (strtotime($start) < strtotime($endDate))
{
$start = date('Y-m-d', strtotime($startDate.'+'.$i.' days'));
$return[] = $start;
$i++;
}
}
return $return;
}
这会导致以下结果:
有没有一种方式可以使用PHP将每个日期保存到MySQL数据库中?数组([0] => 2016-10-10 [1] => 2016-10-11 [2] => 2016-10-12 [3] => 2016-10-13 [4] => 2016-10-14 [5] => 2016-10-15 [6] => 2016-10-16 [7] => 2016-10-17 [8] => 2016-10-18 [9] => 2016-10-19)