例子 :
00:00 22-03-2017, John Wilson
08:00 22-03-2017, Gemma Arterton
16:00 22-03-2017, Arnold Plank
00:00 22-03-2017, Timmy Brouwer
08:00 22-03-2017, John Wilson <- names repeating
16:00 22-03-2017, Gemma Arterton
我正在构建一个轮班系统,它会生成接下来 30 天的时间和日期。我正在尝试获取不同的相关名称以获取日期的回声,但到目前为止还没有运气。这些名称是交互式的,意味着可能只有 1 个和 25 个(可以这么说)。
这是我当前对函数代码的调用:
$month = $shift->date_range(date("Y-m-d"), date('Y-m-d', strtotime("+30 days")), "+" . $shift_facility['facility_shift_duration'] . " hours", "Y/m/d H:i:s", $user_per_facility);
这是我的功能本身:
public function date_range($first, $last, $step = '+1 day', $output_format = 'd/m/Y', $users)
{
$dates = array();
$current = strtotime($first);
$last = strtotime($last);
while ($current <= $last) {
// Add date and time to array $dates
$dates[] = date($output_format, $current) . ';' . $users[0]["user_id"];
//check if we are still in range between the two dates
$current = strtotime($step, $current);
}
return $dates;
}
$users
包含所有用户数据,例如:
array(2) {
[0]=>
array(5) {
["user_id"]=>
string(1) "3"
["user_alias"]=>
string(7) "ND12345"
["user_facility"]=>
string(2) "29"
["user_phone"]=>
string(5) "12345"
["user_name"]=>
string(9) "Jan steen"
}
[1]=>
array(5) {
["user_id"]=>
string(1) "7"
["user_alias"]=>
string(7) "ND68596"
["user_facility"]=>
string(2) "29"
["user_phone"]=>
string(11) "31115648597"
["user_name"]=>
string(8) "John Doe"
}
}
$users[0]["user_id"];
只输出名字,但我需要它们交替(看第一个例子)。
有没有人有任何想法可以为我指明正确的方向或帮助我一点?
提前谢谢^^
编辑:更多细节
我的函数调用在 foreach 中:
foreach ($facility->getfacilities() as $shift_facility) {
$user_per_facility = $user->getusersbyFacilityId($shift_facility['facility_id']);
if (isset($user_per_facility[0]["user_id"])) {
//if shift count > dan db results generate new day
$month = $shift->date_range(date("Y-m-d"), date('Y-m-d', strtotime("+30 days")),
"+" . $shift_facility['facility_shift_duration'] . " hours", "Y/m/d H:i:s", $user_per_facility);
}
}