我在while循环中有一个变量,它正在创建日期。我希望将while循环的每次迭代生成的所有日期都放到while循环之外的数组中。这可能吗?
while($row=mysql_fetch_array($sq))
{
extract($row);
$startDate = date("d-m-Y", strtotime($created_on. ' + '.$days_for_start.' days'));
$end_date = date("d-m-Y", strtotime($created_on. ' + '.$days_for_end.' days'));
}
print_r($end_date);
//should output, 24-03-2017 for number of times the loop is running, in an array.
答案 0 :(得分:1)
$end_date = array();
while($row=mysql_fetch_array($sq))
{
extract($row);
$startDate = date("d-m-Y", strtotime($created_on. ' + '.$days_for_start.' days'));
$end_date[] = date("d-m-Y", strtotime($created_on. ' + '.$days_for_end.' days'));
}
print_r($end_date);
更新了一个
//使用$end_date_tmp
变量作为数组。
$end_date_tmp = array();
while($row=mysql_fetch_array($sq))
{
extract($row);
$startDate = date("d-m-Y", strtotime($created_on. ' + '.$days_for_start.' days'));
$end_date_tmp[] = date("d-m-Y", strtotime($created_on. ' + '.$days_for_end.' days'));
}
print_r($end_date_tmp);