简体   繁体   English

循环调度

[英]Round robin scheduling

I need help on round robin scheduling. 我需要有关循环调度的帮助。 I have appointment,company,users. 我有约会,公司,用户。

eg 2 users in 1 company 例如,在1家公司中有2位用户

Appointment 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. 使用php脚本。 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. 然后,您可以通过$appts进行foreach并构建查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM