title: PHP generate football schedule
body: <p>I have 38 days and 20 clubs (EPL).</p>
  
  <p>How can I generate not repeated matches for this clubs in this days (schedule)?</p>
  
  <p><strong>For example:</strong></p>
  
  <hr>
  
  <p><strong>Day 1:</strong></p>
  
  <p>club1 - club2</p>
  
  <p>club3 - club4</p>
  
  <p>...</p>
  
  <p>club19 - club 20</p>
  
  <hr>
  
  <p><strong>Day 2:</strong></p>
  
  <p>club1 - club3</p>
  
  <p>club2 - club4</p>
  
  <p>...</p>
  
  <p>club20 - club18</p>
  
  <hr>
  
  <p>Each club plays with other two games (home and away). Respectively do not play with himself.</p>
  
  <hr>
  
  <p><strong>My thinks:</strong></p>
  
  <pre><code>    $clubs1 = array();
      $clubs2 = array();
      $days = range(1, 38);
      $calendar = array();
      $pars = array();
  
      $rows = Yii::app()-&gt;db-&gt;createCommand()
          -&gt;select('id')
          -&gt;from('clubs')
          -&gt;queryAll();
  
      foreach ($rows as $item) {
          $clubs1[] = $item['id'];
          $clubs2[] = $item['id'];
      }
  
  
      shuffle($clubs1);
      shuffle($clubs2);
      $total = (count($clubs1) * 2) - 2;
  
      for ($j = 1; $j &lt;= $total; $j ++) {
          $day = $days[$j];
          for ($i = 0; $i &lt; count($clubs1); $i++) {
  
            WHAT I SHOULD DO IN THIS BODY?
  
          }
      }
  </code></pre>