从这里我有 start_date 和 due_date 以及使用此值的其他一些变量我必须制作多维数组,开始日期为2018-01-01
结束日期{ {1}}表示3个时间循环应与相应的日期一起运行。
我的变量
2018-01-03
我的预期输出
$start_date = "2018-01-01";
$start_time = "01:30 PM";
$due_date="2018-01-03";
$due_time = "11:30 AM"
$project="10001";
$assign_to="G2E0357";
答案 0 :(得分:0)
您可以通过代码评论:
中提及的一些步骤进行操作date_default_timezone_set('UTC');
$start_date = "2018-01-01";
$start_time = "01:30 PM";
$due_date="2018-01-03";
$due_time = "11:30 AM";
$project="10001";
$assign_to="G2E0357";
$glopal_array = array();
$data_array = list_days(strtotime($start_date),strtotime($due_date));// get all days in array
foreach($data_array as $item) {//loop in day array
$res_arr_values = array("allocation_date"=>$item,"t_project"=>$project,"t_assign_to"=>$assign_to,"t_start_time"=>$start_time,"t_end_time"=>$due_time);//set up 2d arry with keys
array_push($glopal_array,$res_arr_values);//push the array the global array
}
echo "<pre>";
print_r($glopal_array);//print glopal array
echo "</pre>";
function list_days($date_from,$date_to){
$arr_days = array();
$arr_days[] = date('o-m-d',$date_from);
$day_passed = ($date_to - $date_from); //seconds
$day_passed = ($day_passed/86400); //days
$counter = 1;
$day_to_display = $date_from;
while($counter < $day_passed){
$day_to_display += 86400;
//echo date("F j, Y \n", $day_to_display);
$arr_days[] = date('o-m-d',$day_to_display);
$counter++;
}
$arr_days[] = date('o-m-d',$date_to);
return $arr_days;
}
<强>输出:强>