在这里,我正在为每个员工明智地进行任务分配,几乎我完成了我必须在项目方面做小时计算
<?php
include("dbconfig.php");
include("functions.php");
$sql = "SELECT DISTINCT date_add(date(d_started_on), interval i day) as allocation_date,t_project,t_assign_to,t_start_time,t_end_time FROM ( SELECT date(STR_TO_DATE(t_started_on, '%Y-%m-%d')) as d_started_on, datediff( date(STR_TO_DATE(t_due_on, '%Y-%m-%d')), date(STR_TO_DATE(t_started_on, '%Y-%m-%d')) ) as days,t_project,t_assign_to,t_start_time,t_end_time FROM task ) as base INNER JOIN nums ON i <= days ORDER BY 1";
$mysql = mysql_query($sql);
$productsArray = array();
while($rowRes = mysql_fetch_assoc($mysql)){
$rowRes['allocated_day'] = $rowRes['allocation_date'];
$productsArray[] = $rowRes;
}
$project_name = array();
foreach($productsArray as $key0 => $info) {
$key1 = $info['t_assign_to'];
$key2 = $info['t_project'];
$key3 = $info['allocated_day'];
$project_name[$key1][$key2][$key3] = $info['t_start_time'].' '.$info['t_end_time'];
}
print_r($project_name);
?>
输出
Array
(
[G2E0357] => Array
(
[10001] => Array
(
[2018-01-01] => 01:30 PM 11:30 AM
[2018-01-02] => 01:30 PM 11:30 AM
[2018-01-03] => 01:30 PM 11:30 AM
)
[10008] => Array
(
[2018-01-25] => 10:30 AM 01:30 PM
[2018-01-26] => 10:30 AM 01:30 PM
[2018-01-27] => 10:30 AM 01:30 PM
)
)
[XPL0315] => Array
(
[10008] => Array
(
[2018-01-18] => 11:30 AM 07:30 PM
[2018-01-19] => 11:30 AM 07:30 PM
[2018-01-20] => 11:30 AM 07:30 PM
)
)
)
Explnation
员工ID XPL0315 有一个项目分配( 10008 )。时间线是2018-01-18
上午11:30 INTO 2018-01-20
07:30 PM,
而不是显示 t_start_time 和 t_end_time 。我必须每天计算员工必须工作的小时数
我的办公时间是上午9:30至下午7:30(共10小时)
员工ID XPL0315 和项目ID 10008 有3天的分配但工作时间基于不同的分配,因为
预期的输出应该是这样的
Array
(
[G2E0357] => Array
(
[10001] => Array
(
[2018-01-01] => 6 Hrs
[2018-01-02] => 10 Hrs
[2018-01-03] => 2 Hrs
)
[10008] => Array
(
[2018-01-25] => 9 Hrs
[2018-01-26] => 10 Hrs
[2018-01-27] => 4 Hrs
)
)
[XPL0315] => Array
(
[10008] => Array
(
[2018-01-18] => 7 Hrs
[2018-01-19] => 10 Hrs
[2018-01-20] => 10 Hrs
)
)
)
我认为我们必须采用第一个索引和最后一个索引,
答案 0 :(得分:1)
试试这个
$project_name = array();
foreach($productsArray as $key0 => $info) {
$key1 = $info['t_assign_to'];
$key2 = $info['t_project'];
$key3 = $info['allocated_day'];
/* Add this code */
$start = new DateTime(date("H:i:s", strtotime($info['t_start_time']))); //'10:35:20'
$end = new DateTime(date("H:i:s", strtotime($info['t_end_time'])));//'02:00:45'
$diff = $start->diff( $end );
$hrs = $diff->format( '%H'.' Hrs' ); //'%H:%I:%S' => 02:25:25
$project_name[$key1][$key2][$key3] = $hrs;
/* Add this code */
}