我有工作人員的時間列表。我需要找出是否有任何工作人員的單獨工作,多少分鐘,他們一天工作時間表單獨工作分鐘
| 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 |
隨着Andreas' help單獨工作,以下是得到誰與單獨工作的第一和最後一個人的代碼單獨一分鐘,但不完全正確。因爲如果有三個人在不同的時間單獨工作,這會產生問題。 https://3v4l.org/6OmjO
$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");
@mickmackusa添加日期不是問題,是我感到困惑的計算。因爲我們必須跟蹤所有工作人員,這可能是單獨工作的時間,並計算他/她單獨工作的分鐘數。 – Basit
@mickmackusa我理解他的兩個問題的方式,輸出應該是告訴他誰有一個人待了多久。你如何呈現它可能不是那麼重要,因爲他似乎能夠改變你的輸出到他想要的東西。我可能是錯的,但這就是我對Basit的理解。他還有很多關於PHP的問題和答案,所以我認爲他可以處理你給他的任何輸出。 – Andreas
熱切期待... – Basit