0

我有一个array包含多个团队。我希望每支球队都和其他球队一起比赛。

我曾尝试这样做,for loop但没有任何效果。

数组是这样的。

Array ( [0] => 2 [1] => 3 [2] => 8 [3] => 9 [4] => 11 [5] => 12 )

我想这样做。

[0] - [1]
[0] - [2]
[0] - [3]
[0] - [4]
[0] - [5]

[1] - [2]
[1] - [3]
[1] - [4]
[1] - [5]

[2] - [3]
[2] - [4]
[2] - [5]

[3] - [4]
[3] - [5]

[4] - [5]

我的代码是这样的

    function createMatchesStandings($teams,$homeaway,$round)
    {
        include_once('class_match.php');

        if($homeaway == 0)
        {
            // one way matches
            $numberOfMatches = count($teams) - 1;
            for($i = 0; $i<=$numberOfMatches;$i++)
            {
                $match = new Match();
                $match->standing = $this->id;
                $match->round = $round;
                $match->home_team = $teams[$i];
                $match->away_team = $teams[$i+1];
                $match->week = $i;
                $match->date = '0000-00-00';
                $match->insert();
            }


        }elseif($homeaway == 1)
        {
            // home away matches ($teams * 2) - 2

        }

    }
4

2 回答 2

4

像下面的代码可以帮助你吗?(我希望我理解这个问题。)

$teams=array(1,2,3,4,5);

for($i=0;$i<sizeof($teams);$i++)
  for($j=$i+1;$j<sizeof($teams);$j++)
    echo $teams[$i].' - '.$teams[$j].'<br />';
于 2012-12-08T10:35:22.073 回答
-1

你的数组名称是什么,我可以说你使用 foreach 循环作为

foreach(array["id"] as $key=>$value){
 $team[$id]=$value;// got new aaray as your team
 //now make your code for match between team[id] and array[id] 

   }
于 2012-12-08T10:41:42.900 回答