Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I created a roundrobin function from scratch as i thought it might be easier to get the same results and also allowing me to use arrays filled with strings directly instead of numbers.</p> <p>Because i pull a list of names from a database and add into an array i can now schedule this directly with below function. No extra step needed to link numbers to names etc.</p> <p>Please feel free to try it and if it works then leave a comment. I also have a version which allows for 2 way (home &amp; return) schedule and or shuffle option. If somone is interested in that one then leave a coment as well.</p> <pre><code>&lt;?php /** * @author D.D.M. van Zelst * @copyright 2012 */ function scheduler($teams){ if (count($teams)%2 != 0){ array_push($teams,"bye"); } $away = array_splice($teams,(count($teams)/2)); $home = $teams; for ($i=0; $i &lt; count($home)+count($away)-1; $i++){ for ($j=0; $j&lt;count($home); $j++){ $round[$i][$j]["Home"]=$home[$j]; $round[$i][$j]["Away"]=$away[$j]; } if(count($home)+count($away)-1 &gt; 2){ array_unshift($away,array_shift(array_splice($home,1,1))); array_push($home,array_pop($away)); } } return $round; } ?&gt; </code></pre> <p>How to use, for example create an array like:</p> <pre><code>&lt;?php $members = array(1,2,3,4); ?&gt; </code></pre> <p>or</p> <pre><code>&lt;?php $members = array("name1","name2","name3","name4"); ?&gt; </code></pre> <p>then call the function to create your schedule based on above array:</p> <pre><code>&lt;?php $schedule = scheduler($members); ?&gt; </code></pre> <p>To display the resulted array schedule simply do like below or anyway you like: This little code displays the schedule in a nice format but use it anyway you like.</p> <pre><code>&lt;?php foreach($schedule AS $round =&gt; $games){ echo "Round: ".($round+1)."&lt;BR&gt;"; foreach($games AS $play){ echo $play["Home"]." - ".$play["Away"]."&lt;BR&gt;"; } echo "&lt;BR&gt;"; } ?&gt; </code></pre> <p>Leave a note if it worked for you or if you are interested in the 2-way version with shuffle.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload