Round robin scheduling
I need help on round robin scheduling. I have appointment,company,users.
e.g. 2 users in 1 company
Appo开发者_运维技巧intment 1 user 1 company 1 appointment 2 user 2 company 1 appointment 3 user 1 company 1 appointment 4 user 2 company 1.
Use php script. I am stuck. Anyone one have any suggestion. Please help!
Here is how to implement basic round robin, not sure this is what you ment as the commenters have said you're little vague:
<?php
$appointments = array();
$users = array('Jon', 'Billy', 'George', 'Michael');
for ($i = 0, $max=count($users); $i < $max; $i++) {
for($j = $i+1; $j < $max; $j++) {
$appointments[] = array($users[$i], $users[$j]);
}
}
print_r($appointments);
?>
What you want is the Cartesian product of users, companies.
function getAppts($users, $companies)
{
$appts = array();
foreach ($users as $user) {
foreach ($companies as $company) {
$appts[] = array($user, $company);
}
}
return $appts;
}
$appts = getAppts(array('user1', 'user2'), array('company1'));
This will produce the combinations you need:
Array
(
[0] => Array
(
[0] => user1
[1] => company1
)
[1] => Array
(
[0] => user2
[1] => company1
)
)
The function allows you to add more users or companies and get all the appointment combinations. You can then foreach through $appts
and building your queries.
精彩评论