【发布时间】:2017-12-21 05:03:20
【问题描述】:
我有工作人员的时间清单。我需要了解是否有员工单独工作,以及他们一天单独工作了多少分钟
| staff| start | end |
|:--- |:--- |:--- |
| 1 | 11:05 | 20:00 |
| 2 | 11:00 | 17:00 |
| 3 | 19:00 | 03:00 |
| 4 | 13:00 | 20:00 |
| 5 | 19:00 | 03:00 |
在 Andrea 的帮助下,下面是获取第一个和最后一个单独工作的人的代码,但它并不安静。因为如果有 3 个不同时间的人单独工作,就会出现问题。
$staff = array(1,2,3,4,5);
$start = array("11:05", "11:00", "19:00", "13:00", "19:00");
$end = array("20:00", "17:00", "03:00", "20:00", "03:05");
array_multisort($start, $end, $staff);
$aloneStart = (strtotime($start[1]) - strtotime($start[0]))/60; // first and second items are the ones that may be working alone at start
$aloneEnd = (strtotime($end[count($end)-1]) - strtotime($end[count($end)-2]))/60; // last and second to last are the ones that may be working alone at end
if($aloneStart > 0){
$staffAloneStart = $staff[0]; //must be the first who worked alone
echo "minutes alone at start: " . $aloneStart . " and it was " . $staffAloneStart . "\n";
}
if($aloneEnd > 0){
$staffAloneEnd = $staff[count($end)-1]; // must be the last to end that worked alone
echo "minutes alone at end: " . $aloneEnd . " and it was " . $staffAloneEnd . "\n";
}
$aloneTime = intval($aloneStart)+intval($aloneEnd);
echo "total time alone " . $aloneTime;
使用以下数组,您会看到第一个用户的分钟数需要超过 5 分钟,因为他在晚上更多地独自工作。
$staff = array(1, 2, 3, 4, 5);
$start = array("11:05", "11:10", "19:00", "13:00", "19:00");
$end = array("20:00", "17:00", "03:00", "16:00", "03:00");
【问题讨论】:
-
是的:预计Stack Overflow users? 的研究工作量是多少
-
@RiggsFolly 我不需要解决方案,我只需要一些关于如何实施的指导。
-
这是存储在数据库中,还是只是一个数组?
-
@Qirel 数据库,但是获取并制作成数组。