【发布时间】:2016-10-08 10:53:04
【问题描述】:
我是 PHP 数组的新手...但我创建了一个数组来获取已在表单中提交的 2 个日期之间的所有日期。
见下文:
$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;
}
结果如下
数组 ([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 日)
有没有办法使用 PHP 将这些日期中的每一个保存到 MySQL 数据库中?
【问题讨论】: