Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6196699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:41:21+00:00 2026-05-24T03:41:21+00:00

I have a problem that I have been thinking about, but I can’t really

  • 0

I have a problem that I have been thinking about, but I can’t really figure out how to solve it. I am writing software for my local sports club, which has an international tourney coming up soon. I would like to have the administration as automised as possible. I have done a great deal already, but now I’m struggling to get one last thing done.

Say, you have an array with 4 teams, namely team A, B, C and D. What I would like to do, is to create a new array, with all possible games. That isn’t so hard to do, but the difficulty lies in the fact that I would like to have some sort of sorting capability in it. The way I have it now, the games are created like this:

['A - B', 'A - C', 'A - D', 'B - C' , ...]

What I would like to have is something like this:

['A - B', 'C - D', 'A - C', 'B - D', 'A - D', ...]

Does anyone know how I could achieve this? any help would be greatly appreciated.

Sidenote: A – B = B – A, We don’t need a two-way competition (but I can program this bit myself if necessary).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:41:22+00:00Added an answer on May 24, 2026 at 3:41 am

    I have found the solution to my problem.
    it is shown below 🙂

    function sort_array($teams)
    {
        $num_teams = count($teams);
        if(count($teams)%2 != 0)
        {
            $ghost = array();
            $ghost["name"] = "ghost";
    
            array_push($teams, $ghost);
            $num_teams++;
        }
    
        $games = array();
        for($i = 1; $i < $num_teams; $i++)
        {
            if($teams[$i]["name"] != "ghost")
                    array_push($games, $teams[0]["name"] . " - " . $teams[$i]["name"]);
    
            for($k = 1; $k <= $num_teams; $k++)
            {
                $index_team_1 = ($i+$k < $num_teams) ? $i+$k : $i+$k-$num_teams;
                $index_team_2 = ($i-$k > 0) ? $i-$k : $i-$k+$num_teams-1;
    
                $temp_add = array();
                $temp_add["team_1"] = $teams[$index_team_1]["name"];
                $temp_add["team_2"] = $teams[$index_team_2]["name"];
    
                if($teams[$index_team_1]["name"] != "ghost" && 
                    $teams[$index_team_2]["name"] != "ghost" &&
                    $index_team_1 != 0 &&
                    $index_team_2 != 0 &&
                    $temp_add["team_1"] != $temp_add["team_2"] &&
                    !in_array($temp_add["team_1"] . " - " . $temp_add["team_2"], $games) &&
                    !in_array($temp_add["team_2"] . " - " . $temp_add["team_1"], $games))
                    {
                        array_push($games, $temp_add["team_1"] . " - " . $temp_add["team_2"]);
                    }
            }
        }
    
        return $games;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tricky problem that I've been messing about with for a few
This is a really weird problem that I have been having. When I download
I've been thinking about this problem for a while and have yet to come
Here's a little problem I've been thinking about for a while now that I
I have a dilemna that needs I've been thinking a while but still haven't
I have the problem that an specific step in Ant can only be executed
I am looking for some input on something I have been thinking about for
Does anyone know if the problems that have been affecting Stack Overflow with regards
I have a problem that confuses my users, being that although an item is
I have a problem that I would like have solved via a SQL query.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.